Count() Function with GROUP BY Clause
Using the Count() Function with GROUP BY Clause
Query-5
CREATE TABLE package01 ( user_id INTEGER PRIMARY KEY AUTOINCREMENT, item VARCHAR(10), mrp INTEGER, sp INTEGER ); INSERT INTO package01 (item, mrp, sp) VALUES ('book1', 250, 240); INSERT INTO package01 (item, mrp, sp) VALUES ('book2', 350, 320); INSERT INTO package01 (item, mrp) VALUES ('book3', 400); INSERT INTO package01 (item, mrp) VALUES ('book3', 400); SELECT item, COUNT(*) FROM package01 GROUP BY item;
Output:
COUNT() Function in MySQL
Count() function in MySQL is used to find the number of indexes as returned from the query selected.
Features
- This function finds the number of indexes as returned from the query selected.
- It comes under Numeric Functions.
- It accepts only one parameter namely expression.
- This function ignores NULL values and doesn’t count them.
Syntax:
COUNT(expression)
- Parameter values: This method accepts only one parameter as given below:
- Expression: A specified expression can either be a field or a string-type value.
- Returns: It returns the number of indexes as returned from the query selected.
Contact Us