Write SQL and Python, run instantly in your browser, and track your progress.
You are a Data Analyst at Amazon. Your team is building a new customer data platform, and you've been tasked with migrating customer data from a recently acquired subsidiary. The initial data dump is messy. Inconsistent formatting in phone numbers and email addresses is causing major headaches: marketing emails are bouncing, customer service reps are dialing wrong numbers, and duplicate customer profiles are being created.
To prevent this data chaos, you need to write a SQL query to standardize the contact information from the customers table before the final import. Your query must produce a clean, standardized list of customers with lowercased emails, cleaned phone numbers containing only digits, and uppercased country codes, sorted alphabetically by email for easy review.
| Column Name | Type |
|---|---|
| customer_id | INTEGER |
| full_name |
You are a Data Analyst at Amazon. Your team is building a new customer data platform, and you've been tasked with migrating customer data from a recently acquired subsidiary. The initial data dump is messy. Inconsistent formatting in phone numbers and email addresses is causing major headaches: marketing emails are bouncing, customer service reps are dialing wrong numbers, and duplicate customer profiles are being created.
To prevent this data chaos, you need to write a SQL query to standardize the contact information from the customers table before the final import. Your query must produce a clean, standardized list of customers with lowercased emails, cleaned phone numbers containing only digits, and uppercased country codes, sorted alphabetically by email for easy review.
| Column Name | Type |
|---|---|
| customer_id | INTEGER |
| full_name |
| TEXT |
| TEXT |
| TEXT |
| TEXT |
| phone | TEXT |
| phone | TEXT |
| city | TEXT |
| city | TEXT |
| state | TEXT |
| state | TEXT |
| country | TEXT |
| country | TEXT |
| created_at | TEXT |
| created_at | TEXT |
| customer_id | full_name | phone | city | state | country | created_at | |
|---|---|---|---|---|---|---|---|
| 1 | Sophia Lewis | sophia.lewis@gmail.com | San Diego | CA | US | 2024-10-10 19:19:27 |
| customer_id | full_name | phone | city | state | country | created_at | |
|---|---|---|---|---|---|---|---|
| 1 | Sophia Lewis | sophia.lewis@gmail.com | San Diego | CA | US | 2024-10-10 19:19:27 |
| customer_id | email_lower | phone_digits | country_upper |
|---|---|---|---|
| 45 | ahmed_collins@icloud.com | +12719915573 | CA |
| 46 | anakamura@aol.com | +61252793925 | AU |
| 3 | andrea_miller@zoho.com | +18034841106 | CA |
| 12 | ann.o'connor96@hotmail.com | +15704243266 |
| customer_id | email_lower | phone_digits | country_upper |
|---|---|---|---|
| 45 | ahmed_collins@icloud.com | +12719915573 | CA |
| 46 | anakamura@aol.com | +61252793925 | AU |
| 3 | andrea_miller@zoho.com | +18034841106 | CA |
| 12 | ann.o'connor96@hotmail.com | +15704243266 |
Showing first 5 of 50 rows. Customer contacts with standardized emails, phones, and countries sorted alphabetically by email.
Showing first 5 of 50 rows. Customer contacts with standardized emails, phones, and countries sorted alphabetically by email.
1. Output Columns:
customer_id: The customer's unique identifieremail_lower: The customer's email address, converted to all lowercasephone_digits: The customer's phone number, stripped of all common punctuation (-, (, ), .) and spaces, leaving only digits; if NULL, return empty string ('')1. Output Columns:
customer_id: The customer's unique identifieremail_lower: The customer's email address, converted to all lowercasephone_digits: The customer's phone number, stripped of all common punctuation (-, (, ), .) and spaces, leaving only digits; if NULL, return empty string ('')| 2 | Marilyn Kelly | marilynkelly@yahoo.com | New York | NY | US | 2024-11-30 08:33:24 |
| 2 | Marilyn Kelly | marilynkelly@yahoo.com | New York | NY | US | 2024-11-30 08:33:24 |
| 3 | Andrea Miller | andrea_miller@zoho.com | +1-803-484-1106 | Winnipeg | MB | CA | 2025-06-22 16:35:50 |
| 3 | Andrea Miller | andrea_miller@zoho.com | +1-803-484-1106 | Winnipeg | MB | CA | 2025-06-22 16:35:50 |
| 4 | Luis Green | lgreen@aol.com | +1-544-304-2519 | San Antonio | TX | US | 2025-01-26 13:10:44 |
| 4 | Luis Green | lgreen@aol.com | +1-544-304-2519 | San Antonio | TX | US | 2025-01-26 13:10:44 |
| 5 | Anthony Alvarez | anthonya@protonmail.com | +1-749-327-7201 | Los Angeles | CA | US | 2024-10-01 14:28:15 |
| 5 | Anthony Alvarez | anthonya@protonmail.com | +1-749-327-7201 | Los Angeles | CA | US | 2024-10-01 14:28:15 |
| US |
| US |
| 5 | anthonya@protonmail.com | +17493277201 | US |
| 5 | anthonya@protonmail.com | +17493277201 | US |
country_upper: The customer's country code, converted to all uppercasecountry_upper: The customer's country code, converted to all uppercase2. Filtering:
2. Filtering:
customers tablecustomers table3. Ordering:
3. Ordering:
email_lower (ascending)customer_id (ascending)email_lower (ascending)customer_id (ascending)