MYSQL GROUP BY Clause

The GROUP BY statement is often used with aggregate functions like COUNT, MAX, MIN, SUM, AVG to group the result-set by one or more columns.
The MYSQL GROUP BY Clause is used to collect data from multiple records and group the result by one or more column. It is generally used in a SELECT statement.

MYSQL GROUP BY Syntax

SELECT field_name(s)
FROM table_name
WHERE condition
GROUP BY field_name(s)
ORDER BY field_name(s);

MYSQL Example:
The following MYSQL Query lists the number of office in each city:

SELECT COUNT(office_id)as number_of_office,address FROM tbloffice GROUP BY address

Output :

 

number_of_office address
3 CHHAPI
5 IDAR
5 KAPADVANJ
1 KHERALU
2 Modasa
9 PALANPUR
1 SIDDHAPUR

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

55049