runtime
Warehouse and Reporting · milestone 02 / 06

milestone 2/6 Silver: clean, map & deduplicate

Clean values, apply mappings and remove duplicate records.

Warehouse and Reporting · Profile raw CRM/sales records, build Silver and Gold tables in the disposable lab, explore the fact table, and publish repeatable reporting logic.

approach

Silver applies explicit quality rules. Normalize keys and text, keep the latest customer version, map country codes, and exclude missing keys. With equal version timestamps production logic needs an additional reliable tie-breaker; this sample has none.

worked-example.sql
CREATE TEMP TABLE silver_customers AS
WITH ranked AS(
  SELECT
    *,
    ROW_NUMBER() OVER(PARTITION BY TRIM(raw_id) ORDER BY updated_at DESC) AS rn
  FROM bronze_customers
  WHERE raw_id IS NOT NULL AND TRIM(raw_id)<>''
)
SELECT
  TRIM(raw_id) AS customer_id,
  TRIM(name) AS name,
  CASE UPPER(TRIM(country))
    WHEN 'US' THEN 'United States'
    WHEN 'USA' THEN 'United States'
    WHEN 'UK' THEN 'United Kingdom'
    WHEN 'GB' THEN 'United Kingdom'
    WHEN 'IND' THEN 'India'
    WHEN 'CA' THEN 'Canada'
    ELSE UPPER(TRIM(country))
  END AS country
FROM ranked
WHERE rn=1;
SELECT customer_id,name,country
FROM silver_customers;

data for this milestone

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

challenge 1

Create TEMP silver_customers: trim keys/names; discard NULL/empty keys; keep latest updated_at per trimmed key.

Map US/USA→United States, GB/UK→United Kingdom, IND→India, CA→Canada.

Return customer_id,name,country.

what to return

Columns
customer_idnamecountry in this order
Rows
any order
Also checked
TEMP / table changes from your script
challenge-1.sql
 
3 steps left · check both queries and pass the concept checkOpen the reportNext milestone
Silver: clean, map & deduplicate — Warehouse and Reporting · Runtime