runtime
71 / 88

lesson 71 Warehouse & reporting projects · advanced

Bronze: inspect raw data before cleaning

Inspect incoming records before making cleaning decisions.

the idea

Bronze preserves source records for traceability. Profile missing keys, duplicates, dates, and type mismatches before writing cleaning rules. Do not silently erase rows without documenting why. These source rows are fictional, inspired by common CRM/catalog/sales issues.

tables in this lesson

The challenges use this data. Each column shows its type underneath; → marks a link to another table.

bronze_customers4 columns · 7 rows
raw_idtextnametextcountrytextupdated_attext
C001 Alice USA2025-01-01
C001 Alice Nguyen US2025-01-05
C002BenGB2025-01-02
C003 Cara UK2025-01-03
C004DevIND2025-01-04

showing 5 of 7 rows

bronze_sales6 columns · 13 rows
row_idinteger · keycustomer_idtextproduct_idtextquantitytextsalestextorder_datetext
1C001P012242025-01-01
2 C002 P031802025-01-02
3C001P021452025-01-15
4C003P0422402025-02-01
5C004P0321602025-02-05

showing 5 of 13 rows

example

The idea in one query. Press Run to see what it returns; running examples never affects your progress.

example.sql
SELECT TRIM(raw_id) AS customer_id,COUNT(*) AS versions
FROM bronze_customers
WHERE raw_id IS NOT NULL
GROUP BY TRIM(raw_id)
HAVING COUNT(*)>1;

Watch for: A date parse check is not a complete calendar validation policy; production rules must also define format and acceptable ranges.

build it step by step

Each step changes one thing. Run them in order and watch the result change.

  1. Preserve the raw input. Note duplicate C001, spaces, and the missing key.

    step-1.sql
    SELECT *
    FROM bronze_customers;
  2. Profile duplicates. Normalize keys for analysis without modifying the Bronze table.

    step-2.sql
    SELECT TRIM(raw_id) AS customer_id,COUNT(*) AS versions
    FROM bronze_customers
    WHERE raw_id IS NOT NULL
    GROUP BY TRIM(raw_id)
    HAVING COUNT(*)>1
  3. Inspect rejected dates. The invalid source row remains traceable.

    step-3.sql
    SELECT row_id,order_date
    FROM bronze_sales
    WHERE date(order_date) IS NULL

challenge 1

Return customer_id (trimmed raw_id) and versions for non-NULL duplicate customer keys in bronze_customers. Keep only keys with more than one version.

Return customer_idversionsany row order

challenge-1.sql
 
To master this lesson, solve both challenges without hints and pass the concept check. 3 of 3 to go.