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 

  1. This function finds the number of indexes as returned from the query selected.
  2. It comes under Numeric Functions.
  3. It accepts only one parameter namely expression.
  4. 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.

Similar Reads

Using the COUNT() Function

Query-1...

Count() With Where Clause

Query-3...

Count() Function with GROUP BY Clause

Using the Count() Function with GROUP BY Clause...

Contact Us