Sign in to run and submit your work
Reading is open to everyone. Running code and saving drafts need an account so your work is yours and comes back on your next visit.
or
CODE WORKSPACE
Return customer_id, old_tier, new_tier, old_valid_from, old_valid_to, new_valid_from, and new_valid_to.
Result columns · in this order
customer_idold_tiernew_tierold_valid_fromold_valid_tonew_valid_fromnew_valid_toHow to approach it
Join clean_stage to dim_customer_history where is_current = 1.
Sample input
| customer_id | old_tier | new_tier | updated_at |
|---|---|---|---|
| 101 | silver | gold | 2026-03-05 10:00:00 |
| 104 | gold | platinum | 2026-03-05 12:30:00 |
2 rows — all rows shown.
Expected output
| customer_id | old_tier | new_tier | old_valid_to | new_valid_from |
|---|---|---|---|---|
| 101 | silver | gold | 2026-03-04 | 2026-03-05 |
| 104 | gold | platinum | 2026-03-04 | 2026-03-05 |
2 rows — all rows shown.
Constraints
Use the latest staged non-deleted row per customer and only current history rows. Close the old row the day before date(updated_at), open the new row on date(updated_at), and order by customer_id.
Expected skills
SCD2 current-row checks and validity-window reasoning.
Submit for review to find out what your query gets right, what it gets wrong, and how it compares with the best working query for this exercise.
This scenario runs a full workspace — editor, canvas and results side by side. It needs a laptop or desktop to be usable. Open this page on a bigger screen to start building.