Aggregate functions condense many rows into one number — the totals, averages, and counts that fill every business report. Mastering their NULL behaviour and DISTINCT variants prevents subtle reporting errors.
Key Points
- COUNT(*) counts rows; COUNT(col) skips NULLs — they differ!
- SUM and AVG ignore NULLs; use COALESCE(col, 0) to treat them as zero
- COUNT(DISTINCT customer_id) counts unique customers
- MIN/MAX work on dates and strings too, not just numbers
- Combine with GROUP BY for per-category summaries
- GROUP_CONCAT aggregates values into a single string list
.png)