05
Chapter 5
GROUP BY & Aggregation
Folding rows into summaries. GROUP BY, HAVING, ROLLUP, and the aggregate functions that turn data into answers.
In this chapter
24
queries, easy → advanced
- 001Count employees by departmentRead
- 002Sum total sales per customerRead
- 003Find average salary by job titleRead
- 004Monthly revenue reportRead
- 005Products sold per categoryRead
- 006HAVING: departments with budget over 1 millionRead
- 007ROLLUP: hierarchical sales totalsRead
- 008CUBE: all combinations of groupingsRead
- 009GROUPING SETS: custom aggregation combinationsRead
- 010Percentile: find median salaryRead
- 011STRING_AGG: list employee names per departmentRead
- 012FILTER clause in aggregationRead
- 013Mode: most common salary valueRead
- 014Pivot-style aggregation using CASERead
- 015Weighted average calculationRead
- 016Revenue by month using TO_CHARRead
- 017Average order value by customer tierRead
- 018Salary distribution by bandRead
- 019Top 3 products by revenue in each categoryRead
- 020Daily active users (orders per day)Read
- 021Cohort size by signup monthRead
- 022Product pairs frequently bought togetherRead
- 023Classic: department with highest average salaryRead
- 024Histogram: salary distribution with width_bucketRead