SQL GROUP BY
An SQL clause that sorts rows into groups sharing the same field value, then applies an aggregate like AVG or COUNT to each group, giving one result row per group (e.g. average score per class).
Understanding SQL GROUP BY in VCE Spreadsheets, SQL & Visualisation
What it does: GROUP BY shop makes one group per shop and SUM(sales) adds up the sales inside each group. ORDER BY comes after GROUP BY and sorts the group results. DESC puts the highest average at the top. GROUP BY class splits the rows into one group per class, so AVG works out the average for each group. Without it, SQL cannot pair the class column with a single average. The column you group by (year) goes after GROUP BY. The aggregate function COUNT(*) belongs in the SELECT list, not after GROUP BY.
Common mistakes: The clause is called GROUP BY. The word BY is missing. It should be GROUP BY class;. GROUP BY needs a column to make groups from, not the table name. To count players in each team it should be GROUP BY team;.
Free printable worksheet with full answer key — or add this module to a class and your students practise it interactively.
This module's key terms are also in a printable crossword (Modules 55–70) and word search (Modules 55–86).
Take this worksheet further — free with Cloodit
Each concept is reinforced from every angle — learned, then applied, then tested.
Cloodit turns curriculum-aligned coding content into journeys students work through one biome at a time.
Over 100 of them, across seven natural biomes.
Turns their work into revision material ready for Flash Cards and Exam study.
Live, competitive practice for the start of the lesson or a teacher-led lesson finisher.
Honour your top performers, or encourage a student who's trying hard — ready to print in seconds.
Quick Questions
Match the Pairs
Key Term
GROUP BYFill in the Blanks
Spot the Error
Student with a class code? Join your class →