SQL/Aggregation 8 min
Aggregation and GROUP BY
Collapse many rows into one number per group.
group byhavingcountsum
Aggregate functions reduce a set of rows to a single value: COUNT, SUM, AVG, MIN, MAX. Used alone they summarise the whole table.
sql · editable
loading editor…
GROUP BY splits the table into buckets first, then applies the aggregate to each bucket. Every column in the SELECT list must either be grouped or aggregated.
sql · editable
loading editor…
WHERE filters rows before grouping; HAVING filters the groups afterwards. If your condition mentions an aggregate, it belongs in HAVING.
sql · editable
loading editor…
practice this