Aggregates are squeeze functions: COUNT, SUM, AVG, MIN and MAX collapse a whole column of rows into a single value.
1 COUNT(*)
Counts how many rows survived the query — the quickest popularity test there is.
2 SUM & AVG
SUM adds the values up; AVG divides the sum by how many values there were.
3 MIN & MAX
The smallest and largest value — the two boundaries of the column.
4 One row out
Without GROUP BY, an aggregate query returns exactly one summary row.
Many rows in, one number out
COUNT(*)1Counts how many rows survived the query — the quickest popularity test there is.
SUM & AVG2SUM adds the values up; AVG divides the sum by how many values there were. MIN & MAX3The smallest and largest value — the two boundaries of the column. One row out4Without GROUP BY, an aggregate query returns exactly one summary row. 4 building blocks make up Many rows in, one number out
Press play: the engine reads all six rows, then five aggregates squeeze them into one summary row.
SELECT COUNT(*), SUM(score), AVG(score),
MIN(score), MAX(score)
FROM students;
students
| id | name | score | city |
|---|
| 1 | Ava | 92 | Oslo |
| 2 | Ben | 82 | Oslo |
| 3 | Chloe | 85 | Lima |
| 4 | Dev | 68 | Lima |
| 5 | Emma | 95 | Oslo |
| 6 | Finn | 88 | Paris |
| COUNT(*) | SUM(score) | AVG(score) | MIN(score) | MAX(score) |
|---|
| press play — rows will appear here |
Step 1/5FROM scans students — aggregates need to see every row before they can answer.
Click each stage: aggregates sit at the end of the normal query pipeline.
Two queries, one table. Careful — WHERE runs before the aggregate in the second one.
Your predicted output — one line per console line
Hint: WHERE runs before the aggregate — only rows scoring above 90 are around to be counted.
Click a function, then click its job to lock the pair.
5 conceptsTap a card to expand ?COUNT(*)drops into place
?SUM(score)drops into place
?AVG(score)drops into place
?MIN / MAXdrops into place
?Aggregatedrops into place
01COUNT counts rows, SUM adds, AVG divides, MIN and MAX find the edges.
02Aggregates look at every surviving row — after WHERE has done its trimming.
03No GROUP BY means exactly one result row, whatever the table size.
04AVG = SUM / COUNT — check that by hand to trust the engine.
05NULLs are skipped by SUM, AVG, MIN and MAX (COUNT(*) never skips rows).