Skip to content

Grouping with GROUP BY

Handout

Grouping rows with GROUP BY

An aggregate like AVG normally summarises the whole table into one number. GROUP BY splits the rows into groups that share a value, and gives one summary row per group:

SELECT form, COUNT(*) AS n, ROUND(AVG(score), 2) AS avg_score
FROM student
GROUP BY form;

This gives one row for each form, with that form's count and average.

GROUP BY collapses rows that share a value into one row per group, summing the rest

Handout

Log in or create account

IGCSE & A-Level