Loading...
Slowly Changing Dimension Type 2
A hard SQL interview practice problem on DataDriven. Write and execute real sql code with instant grading.
- Domain
- SQL
- Difficulty
- hard
- Seniority
- senior, staff
Problem
We maintain a slowly changing dimension (Type 2) for customer addresses. Each customer_id can appear multiple times, once per address change. The current record is the one where last_name is NULL. Find each customer's current country and how many times they have moved (total records minus 1). Show customer_id, first_name, current country, and move count.
Practice This Problem
Solve this SQL problem with real code execution. DataDriven runs your SQL queries against a live PostgreSQL database and grades it instantly.