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_idtext | nametext | countrytext | updated_attext |
|---|---|---|---|
| C001 | Alice | USA | 2025-01-01 |
| C001 | Alice Nguyen | US | 2025-01-05 |
| C002 | Ben | GB | 2025-01-02 |
| C003 | Cara | UK | 2025-01-03 |
| C004 | Dev | IND | 2025-01-04 |
showing 5 of 7 rows