Chapter 4 · 6 levels
Aggregates and GROUP BY
Turn rows into numbers: COUNT, SUM, AVG, MIN, MAX, then break them down by group with GROUP BY and filter groups with HAVING.
StartThis is the chapter where SQL starts producing the numbers people put in slides. “How many orders?”, “revenue per channel?”, “which customers ordered more than ten times?” are all aggregate queries.
You will learn the difference between COUNT(*), COUNT(column) and COUNT(DISTINCT column),
how to compute revenue correctly from order lines, how GROUP BY splits a table into groups, and
when a condition belongs in WHERE versus HAVING. The boss level is a performance snapshot with
product, returns and conversion numbers.
Levels
- How many customers came from referrals?
from Lauren Hayes, Email Marketing Manager
count, count distinct, null, aggregates
- Why does this query fail?
from Tyler Morgan, Junior Data Engineer
execution order, where vs having, aggregates
- Boss: performance snapshot
from Megan Collins, Head of Sales
group by, sum, avg, having, conversion rate, top n