Turn raw rows into the summaries a report needs — counts, totals, averages and per-category breakdowns — using PostgreSQL's aggregate functions, GROUP BY and HAVING. You will finish able to summarise data for reporting, filter groups correctly, count distinct values and produce subtotals with ROLLUP.
Watch the free preview
Counting rows with COUNT — free to watch, no account needed.
What you'll learn
- Summarise data for reporting with COUNT, SUM, AVG, MIN and MAX
- Group rows by one or more columns with GROUP BY
- Filter groups correctly using HAVING rather than WHERE
- Count distinct values and combine joins with aggregation
- Produce subtotals and grand totals with GROUPING SETS and ROLLUP
Syllabus
Aggregate Functions — the Basics
Counting rows with COUNTFree preview
Totals and averages with SUM, AVG, MIN and MAX
Grouping Rows with GROUP BY
GROUP BY — one summary per category
Multi-column grouping and aggregating across joins
Filtering Groups and Counting Distinct
HAVING versus WHERE
DISTINCT and counting unique values
Advanced Aggregation for Reporting
Subtotals with GROUPING SETS, ROLLUP and CUBE
FILTER, conditional aggregates and building a report
Lab — 10 Exercises & Solutions
Exercises 1–5
Exercises 6–10