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 the latest staged row per non-null customer_id with customer_id, email, tier, is_deleted, updated_at, and batch_id.
Result columns · in this order
customer_id | Business key for the customer; one row is intentionally NULL for key validation practice. |
email | Customer email from the source system. |
tier | Customer tier attribute. |
is_deleted | 1 when the source row is an explicit tombstone. |
updated_at | Source update timestamp. |
batch_id | Ingestion batch identifier used as a deterministic tie-breaker. |
How to approach it
Filter null keys, rank each customer, then keep the newest row.
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 |
| null | ghost@example.com | silver | 0 | 2026-03-05 13:00:00 | 7001 |
| 106 | fay@example.com | silver | 0 | 2026-03-04 23:30:00 | 6999 |
8 rows — all rows shown.
Expected output
| 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@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 |
6 rows — all rows shown.
Constraints
Use ROW_NUMBER partitioned by customer_id ordered by updated_at DESC, batch_id DESC. Exclude NULL customer_id rows, keep row_num = 1, and order by customer_id.
Expected skills
Staging hygiene, deterministic tie-breaking, and one-row-per-key merge sources.
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.