Data Cleaning Exercises

Learning path · SQL

SQL analyst: cleaning in DuckDB

Validate before you cast, build ordered exception reports, deduplicate with window functions and join without fan-out.
  1. 1.

    Lesson · 8 min

    Trim the right characters, and only those

    DuckDB's trim removes spaces only.

  2. 2.

    Exercise · beginner

    Join orders to customers without matching blanks

    NULL keys and LEFT JOIN.

  3. 3.

    Lesson · 10 min

    Validate before you cast in SQL

    regexp_full_match before CAST; ordered CASE.

  4. 4.

    Exercise · intermediate

    Validate quantities and prices against ranges

    First failing reason with one CASE.

  5. 5.

    Lesson · 10 min

    Find the row grain before removing duplicates

    Partition by the grain.

  6. 6.

    Exercise · intermediate · Pro

    Deduplicate order lines at the right grain

    QUALIFY row_number().

  7. 7.

    Exercise · intermediate · Pro

    Resolve customer records by normalized email

    Survivor rules with an explicit rank.

  8. 8.

    Lesson · 10 min

    Pivot without inventing zeros

    Conditional aggregation without ELSE 0.

  9. 9.

    Exercise · intermediate · Pro

    Pivot monthly values, keeping zeros and gaps apart

    Pivot keeping gaps.

  10. 10.

    Exercise · intermediate

    Unpivot survey answers without inventing scores

    UNPIVOT drops NULLs by default.

  11. 11.

    Exercise · intermediate

    Clean an order-line export

    A full export with five reasons.