Counting and summarizing
Collapse many rows into one number.
One number from many rows
Aggregate functions reduce a whole column to a single value:
- COUNT(*) — number of rows
- SUM(price), AVG(price) — total / average
- MIN(price), MAX(price) — smallest / largest
SELECT COUNT(*) AS books, AVG(price) AS avg_price
FROM books;
Aggregates ignore NULL (except COUNT(*)). They also respect WHERE, so you can summarize a subset.