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 snapshot for each order_id.
Result columns · in this order
order_id | Order identifier that can repeat across snapshots. |
buyer_id | Customer identifier. |
status | Snapshot status at this update time. |
total_amount | Order total in dollars. |
updated_at | Snapshot update timestamp. |
How to approach it
Rank snapshots first, then filter in an outer query.
Sample input
| order_id | status | updated_at |
|---|---|---|
| 1001 | paid | 2026-01-12 09:00:00 |
| 1001 | shipped | 2026-01-13 10:00:00 |
| 1002 | paid | 2026-01-12 10:30:00 |
| 1004 | paid | 2026-01-15 14:30:00 |
| 1004 | shipped | 2026-01-16 12:20:00 |
| 1008 | shipped | 2026-01-26 10:30:00 |
6 rows — all rows shown.
Expected output
| order_id | buyer_id | status | total_amount | updated_at |
|---|---|---|---|---|
| 1001 | 1 | shipped | 80 | 2026-01-13 10:00:00 |
| 1002 | 3 | paid | 120 | 2026-01-12 10:30:00 |
| 1004 | 1 | shipped | 220 | 2026-01-16 12:20:00 |
| 1008 | 4 | shipped | 150 | 2026-01-26 10:30:00 |
4 rows — all rows shown.
Constraints
Use ROW_NUMBER partitioned by order_id ordered by updated_at DESC, then keep row_num = 1.
Expected skills
Window deduplication and CTE filtering.
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.