lesson 72 Warehouse & reporting projects · advanced
Silver: clean, map & deduplicate
Clean values, apply mappings and remove duplicate records.
the idea
Silver applies explicit, documented rules: trim keys and text, drop rows with no usable key, keep the latest version of each customer, and map inconsistent country codes to one spelling. Write the rules so a reviewer can see exactly why each row was kept, changed or excluded.
Dataset: Retail
The tables the challenges use, with their first 6 rows. Under each column name: the kind of value it holds, and which table it links to.
bronze_customers4 columns · 1,689 rows
| raw_idtext | nametext | countrytext | updated_atdate & time |
|---|---|---|---|
| 15600 | Amelia Smith | GB | 2010-04-25 09:00:00 |
| 15600 | Amelia Smith | united kingdom | 2010-07-01 09:00:00 |
| 15600 | Amelia Smith | United Kingdom | 2011-07-01 09:00:00 |
| 17600 | Amelia Smith | UK | 2011-11-22 09:00:00 |
| 18000 | Amelia Smith | United Kingdom | 2010-05-24 09:00:00 |
| 12420 | Amelia Jones | Cyprus | 2011-10-07 09:00:00 |
- raw_idtext
- 15600
- nametext
- Amelia Smith
- countrytext
- GB
- updated_atdate & time
- 2010-04-25 09:00:00
- raw_idtext
- 15600
- nametext
- Amelia Smith
- countrytext
- united kingdom
- updated_atdate & time
- 2010-07-01 09:00:00
- raw_idtext
- 15600
- nametext
- Amelia Smith
- countrytext
- United Kingdom
- updated_atdate & time
- 2011-07-01 09:00:00
- raw_idtext
- 17600
- nametext
- Amelia Smith
- countrytext
- UK
- updated_atdate & time
- 2011-11-22 09:00:00
- raw_idtext
- 18000
- nametext
- Amelia Smith
- countrytext
- United Kingdom
- updated_atdate & time
- 2010-05-24 09:00:00
- raw_idtext
- 12420
- nametext
- Amelia Jones
- countrytext
- Cyprus
- updated_atdate & time
- 2011-10-07 09:00:00
first 6 of 1,689 rows · your queries use all of them
worked example
Run these steps in order to see the idea before you write your own query. The step marked “the pattern” is what the challenges ask for. Running the example does not count toward progress.
See country spelling variants. Run this on Bronze. UK, GB, and full names show up as separate groups—Silver will map them to one country label.the pattern
example.sqlSELECT UPPER(TRIM(country)) AS raw_country, COUNT(*) AS rows FROM bronze_customers GROUP BY raw_country ORDER BY rows DESC;
See duplicate versions of one customer. Customer 12347 appears several times with different updated_at values; Silver keeps only the latest row per trimmed key.
step-2.sqlSELECT raw_id, name, country, updated_at FROM bronze_customers WHERE TRIM(raw_id) = '12347' ORDER BY updated_at;
common mistake
A new surrogate key is not deduplication: numbering every Bronze row gives one customer several keys.