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 exactly customer_id and load_action for the latest non-null staged row per customer. Use these action labels only: insert, update, unchanged, and delete_candidate.
Result columns · in this order
customer_idload_actionHow to approach it
Build ranked_stage, clean_stage, then LEFT JOIN the current dimension and label the action.
Sample input
| customer_id | tier | is_deleted | updated_at | batch_id | |
|---|---|---|---|---|---|
| 101 | ana@example.com | gold | 0 | 2026-03-05 10:00:00 | 7001 |
| 102 | ben@example.com | silver | 0 | 2026-03-05 11:00:00 | 7001 |
| 103 | cy@example.com | bronze | 1 | 2026-03-05 12:00:00 | 7001 |
| 104 | dee-old@example.com | gold | 0 | 2026-03-05 09:00:00 | 7000 |
| 104 | dee@example.com | platinum | 0 | 2026-03-05 12:30:00 | 7001 |
| 105 | eli@example.com | bronze | 0 | 2026-03-05 08:00:00 | 7001 |
| 106 | fay@example.com | silver | 0 | 2026-03-04 23:30:00 | 6999 |
7 rows — all rows shown.
| customer_id | tier | is_active | |
|---|---|---|---|
| 101 | ana@example.com | silver | 1 |
| 103 | cy@example.com | bronze | 1 |
| 104 | dee@example.com | gold | 1 |
| 105 | eli@example.com | bronze | 1 |
| 107 | gus@example.com | silver | 1 |
5 rows — all rows shown.
Expected output
| customer_id | load_action |
|---|---|
| 101 | update |
| 102 | insert |
| 103 | delete_candidate |
| 104 | update |
| 105 | unchanged |
| 106 | insert |
6 rows — all rows shown.
Constraints
Dedupe customer_stage first using ROW_NUMBER ordered by updated_at DESC, batch_id DESC. Ignore NULL customer_id rows. Compare the clean staged rows to dim_customer_current, treat is_deleted = 1 as delete_candidate, and order by customer_id.
Expected skills
Incremental action planning, staging dedupe, target comparison, and CASE labels.
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.