SQL Topic collection
SQL Aggregations SQL Topic exercises
Build reliable SQL metrics from aggregate functions through grain, fan-out, weighted ratios, rollups, percentiles, and approximate counts.
- Published pages
- 16
- Runnable now
- 15
- Difficulty
- Beginner to Advanced
What this collection tests
Skills and query patterns
GROUP BY and HAVING, conditional metrics, stable grain, fan-out prevention, weighted averages, multidimensional totals, percentiles, and exact-versus-approximate distinct counts
Curated exercises
Choose an exercise
Work in the live editor where supported. Read-only solution guides and advanced guided labs state their capability before you choose the next action.
- Exercise 1Easy
Order Value Metric Snapshot
Return one company-wide order count and value summary.
- Aggregation
- Numeric functions
SQLite + PostgreSQL + MySQL + SQL Server live · 1 guided
Open exercise → - Exercise 2Easy
Regional Order Value Baseline
Return one order-volume and value row per region having orders.
- Joins
- Aggregation
- HAVING
SQLite + PostgreSQL + MySQL + SQL Server live · 1 guided
Open exercise → - Exercise 3Medium
Repair Category Summary Grain
Repair it to return order count and revenue per stable category key.
- Joins
- Aggregation
- Filtering
SQLite + PostgreSQL + MySQL + SQL Server live · 1 guided
Open exercise → - Exercise 4Medium
Regional Order Coverage
Return one order-count row per region, including regions with zero orders.
- Joins
- Aggregation
- Sorting
SQLite + PostgreSQL + MySQL + SQL Server live · 1 guided
Open exercise → - Exercise 5Medium
Recurring February Event Types
Return each February 2025 event type having at least two rows, sorted by count descending and name ascending.
- Aggregation
- HAVING
- Date analysis
SQLite + PostgreSQL + MySQL + SQL Server live · 1 guided
Open exercise → - Exercise 6Medium
Unique Business Event Count
Return one company-wide metric counting unique business events.
- Aggregation
- Distinct values
SQLite + PostgreSQL + MySQL + SQL Server live · 1 guided
Open exercise → - Exercise 7Medium
Order Status Scorecard
Return one scorecard row with total and per-status order counts.
- Aggregation
- CASE expressions
- NULL handling
SQLite + PostgreSQL + MySQL + SQL Server live · 1 guided
Open exercise → - Exercise 8Medium
Monthly Order Value Trend
Return one order-volume and value row per calendar year-month.
- Aggregation
- Date analysis
- Type conversion
SQLite + PostgreSQL + MySQL + SQL Server live · 1 guided
Open exercise → - Exercise 9Medium
Regional Category Order Mix
Return one order-count and revenue row per observed region-category key pair.
- Joins
- Aggregation
- Filtering
SQLite + PostgreSQL + MySQL + SQL Server live · 1 guided
Open exercise → - Exercise 10Hard
Regional Weighted Selling Price
Return one weighted selling-price row per reporting region, including regions with no item facts.
- Joins
- Aggregation
- CASE expressions
SQLite + PostgreSQL + MySQL + SQL Server live · 1 guided
Open exercise → - Exercise 11Hard
Revenue Without Join Fan-Out
Return one reconciled item-revenue and captured-payment row per order.
- Joins
- Subqueries
- Aggregation
SQLite + PostgreSQL + MySQL + SQL Server live · 1 guided
Open exercise → - Exercise 12Hard
Governed Monthly KPI Table
Return one governed KPI row per region and calendar month that has an eligible order.
- Joins
- Subqueries
- Aggregation
SQLite + PostgreSQL + MySQL + SQL Server live · 1 guided
Open exercise → - Exercise 13Hard
Department Payroll Contribution
Return one payroll-contribution row per staffed department using all non-NULL employee salaries as the denominator cohort.
- Joins
- Subqueries
- Aggregation
SQLite + PostgreSQL + MySQL + SQL Server live · 1 guided
Open exercise → - Exercise 14Hard
Regional Revenue Rollup
Return detail rows per region-category key, one subtotal per represented region, and one company grand total.
- Joins
- Subqueries
- Aggregation
PostgreSQL live
Open exercise → - Exercise 15Hard
Regional Order-Value Distribution
Return one continuous median and 90th-percentile order-value row per region with eligible values.
- Joins
- Aggregation
- Numeric functions
PostgreSQL live
Open exercise → - Exercise 16Hard
Exact vs Approximate Customer Reach
Return one exact-versus-approximate distinct-customer comparison design for first-half 2025 events.
- Subqueries
- Aggregation
- Filtering
Guided engine comparison
Open guided exercise →
Attempt
Write a query or design from the brief before opening any hints.
Validate
Run active exercises; use the published evidence and declared validation standard for read-only or guided pages.
Explain
Compare the verified answer and explain each choice aloud.
Learn before practicing SQL Aggregations
Strengthen your understanding with these targeted learning topics:
Continue practicing
Build the next SQL skill
Finding Duplicates & Data Quality
Detect identity collisions, profile NULL-aware conflicts, and compare deterministic survivors with production-safe SQL.
Ranking & NTH Value
Solve deterministic ranking, top-N, distribution, positional-frame, and rolling-window problems.
SQL Joins
Practice reliable INNER, LEFT, FULL, CROSS, self, semi, anti, range, temporal, and many-to-many join patterns.
Open the interactive workspace and practice across SQL topics.