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.

Exercises
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. Advanced guided labs state their engine boundary before you open the workspace.

  1. 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
  2. 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
  3. 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
  4. 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
  5. 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
  6. 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
  7. 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
  8. 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
  9. 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
  10. 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
  11. 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
  12. 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
  13. 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
  14. 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
  15. 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
01

Attempt

Write a query or design from the brief before opening any hints.

02

Validate

Run it against the included dataset and inspect the output.

03

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

SQL Practice Online

Open the interactive workspace and practice across SQL topics.