GROUP BY

GROUP BY is used to organize data into groups, often together with aggregation functions like MIN, MAX, COUNT, and AVG.

GROUP BY Syntax

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

You can use AS in your SELECT statement to give a column a new name.

SELECT column_name(s) AS New_Name;

You can filter grouped results using HAVING.

SELECT column_name(s), aggregation_function(column_name)
FROM table_name
WHERE condition
GROUP BY column_name(s)
ORDER BY column_name(s)
HAVING condition_on_aggregation;

Question number:

Up Next: LIMIT & OFFSET

Donate

About

Privacy Policy

Changelog