WeCodeAcademy

Summarising with GROUP BY

Aggregate functions turn many rows into one number: COUNT, SUM, AVG, MIN, MAX. GROUP BY does it per group: one result row for each distinct value of the grouping column. Use HAVING to filter the groups (after summarising), where WHERE filters rows before.

Order of work: FROM, WHERE, GROUP BY, HAVING, SELECT, ORDER BY.

Examplepython
Open in editor »
Quick check

What does HAVING filter?

Your turn: write the code

Print the total units per product as a list of (product, total) tuples ordered by product.

Finish the quick check (and any code exercise) to complete this lesson, or mark it done yourself.

Tip: use the left and right arrow keys to move between lessons.