← SQL basics
Lesson 3 of 4
Aggregates and GROUP BY
Watch, read the card, then practise. COUNT, SUM, AVG · GROUP BY · HAVING
The video for this lesson is being recorded.
Meanwhile, the notes below and the 60-second cards cover the same ideas.
Practise this topicCOUNT, SUM, AVG
Aggregate functions turn many rows into one number.
Remember: Aggregates squash all the matching rows into one result.
GROUP BY
GROUP BY splits rows into groups and gives one summary row per group.
Remember: One output row per group.
HAVING
HAVING filters groups after GROUP BY, the way WHERE filters rows before it.
Remember: Rows: WHERE. Groups: HAVING.
Try the example in Code Lab
SELECT COUNT(*), MAX(marks), AVG(marks) FROM students;