Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Normalize Customer Addresses by Region

MediumSQL · PostgreSQL00:00
I
Practice interviewer
Your interviewer
In session
I
Interviewer

Welcome to the SQL screen.

The question is on your right: Normalize Customer Addresses by Region. Read through the requirements and the three tables first.

Run and submit your code as often as you need. You also have five interviewer messages this session - want to talk through your approach, or are you ready to start coding?

You need to log in / sign up to run or submit.

Problem

You are given raw customer addresses exported from a TELUS Digital support workflow. The data contains inconsistent province and country values such as mixed casing, abbreviations, punctuation, and missing region mappings. Write a PostgreSQL query that returns one row per address with a normalized province code and normalized country name, then classifies each record as normalized, needs_review, or invalid.

Use the lookup tables to match cleaned province and country values. If a province cannot be matched but the country is Canada or the United States, mark the row as needs_review. If the country itself cannot be matched, mark the row as invalid. Otherwise mark the row as normalized.

Schema

customer_addresses
ColumnTypeDescription
address_idPKINTAddress record ID
customer_nameVARCHAR(100)Customer name
street_addressVARCHAR(150)Raw street address
cityVARCHAR(100)City name
province_rawVARCHAR(50)Raw province or state value
country_rawVARCHAR(50)Raw country value
province_reference
ColumnTypeDescription
province_codePKVARCHAR(10)Standard province or state code
province_nameVARCHAR(100)Standard province or state name
country_codeVARCHAR(10)Country code for the province or state
country_reference
ColumnTypeDescription
country_codeVARCHAR(10)Standard country code
country_nameVARCHAR(100)Standard country name
country_aliasPKVARCHAR(100)Accepted raw alias for the country
Tablescustomer_addressesprovince_referencecountry_reference
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results