Aggregate Functions

An aggregate collapses many rows into one value. COUNT, SUM, AVG, MIN, MAX.

Without GROUP BY they run over the whole table and return a single row. With it, they run over each group.

Try it

Add MIN(b.year) AS first and MAX(b.year) AS latest. One group, several summaries, one pass over the data.

loading editor…
real SQLite, in your browser

One row per author. Note SUM ignores the NULL copies for Anthills of the Savannah, so Achebe's total is 25, not unknown.

Group by the id, not just the name. Two people can share a name, and grouping by the name would merge them into one row that belongs to neither. Grouping by a.id, a.name is correct and lets you select the name safely.

Mark this lesson complete

Signed in, your progress follows you to every device.

Next: HAVING and Evaluation Order →
← Back