Outcomes
- • Group data at the right grain with confidence.
- • Use aggregate functions and HAVING correctly.
- • Avoid misleading metrics caused by bad grouping.
Turn thousands of rows into meaningful numbers. COUNT, SUM, AVG, GROUP BY, and HAVING power every dashboard and business report you will ever build.
Professional learning blueprint
Outcomes
Real-world use
Fast study plan
Deep learning journey
Transform raw rows into trusted metrics, summaries, and leadership-ready views.
Define one output row per entity before aggregating.
Compute reliable totals, averages, and coverage metrics.
Apply HAVING correctly for metric thresholds.
Bonus lesson units
1. Statistical aggregates
Use STDDEV_POP, VARIANCE, PERCENTILE_CONT, and PERCENTILE_DISC for distribution analysis.
2. ROLLUP and CUBE for subtotals
Generate subtotals and grand totals automatically with GROUP BY ROLLUP and CUBE.
3. Pivot tables with FILTER
Build cross-tab reports with conditional aggregation — no CASE WHEN needed.
Expanded practice
1. Department headcount
easyReturn headcount per department with deterministic ordering.
2. Compensation KPI table
mediumReturn avg, min, max salary per department with readable aliases.
3. High-performing groups
mediumKeep only groups above salary or volume thresholds using HAVING.
4. Distinct employee coverage
easyCompare COUNT(*) vs COUNT(DISTINCT employee_id) by group.
5. Revenue rollup by category
hardBuild category revenue totals with grouped order metrics.
6. KPI quality audit
mediumAdd count-based quality checks next to each aggregate metric.
7. Bucketed aggregation
hardGroup rows by computed range bucket and aggregate each bucket.
8. Multi-metric dashboard
hardReturn 6+ aggregate metrics in one compact management table.
9. Aggregation sanity check
easyValidate expected number of groups and total row coverage.
10. Filtered aggregate pattern
mediumUse FILTER (WHERE ...) for conditional aggregates.
Study references
Aggregate functions answer the questions that actually matter in business: "How many orders came in last month? What is the average salary per department? Which product category drives the most revenue?"
COUNT(*) for total rows, COUNT(col) to skip NULLsSUM and AVG on numeric columnsMIN and MAX to find extremesGROUP BY — collapse rows that share a value into one summary rowHAVING — filter on the aggregated result (not the raw rows)WHERE, ORDER BY, and LIMITCOUNT(DISTINCT col) to count unique valuesThe Store database (orders, products, categories) and the HR database. You'll build queries like "revenue by product category" and "headcount per department sorted by average salary."
SQL Fundamentals + Filtering & Logic.