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
Turn raw_orders into the staging model the rest of the project builds on. Return order_id, buyer_name, status and total_amount, one row per order. Order by order_id.
Result columns · in this order
order_idbuyer_namestatustotal_amountHow to approach it
The source lands the same order more than once. Decide the grain before you write anything else: ROW_NUMBER() OVER (PARTITION BY order_id ORDER BY loaded_at DESC) is the usual move.
Sample input
| ORDER_ID | Buyer | order_status | amount | loaded_at |
|---|---|---|---|---|
| 5001 | Priory Utilities | PAID | 240.00 | 2026-03-05 20:00:00 |
| 5002 | Bolt Construction | pending | 90.5 | 2026-03-05 22:00:00 |
| 5001 | Priory Utilities | refunded | 240.00 | 2026-03-06 07:10:00 |
| 5003 | Kestrel Hire | Paid | 310 | 2026-03-06 09:15:00 |
4 rows — all rows shown.
Expected output
| order_id | buyer_name | status | total_amount |
|---|---|---|---|
| 5001 | Priory Utilities | refunded | 240 |
| 5002 | Bolt Construction | pending | 90.5 |
| 5003 | Kestrel Hire | paid | 310 |
3 rows — all rows shown.
Constraints
Cast ORDER_ID to INTEGER and amount to REAL. Rename Buyer to buyer_name. Lowercase and trim order_status. Where an order was loaded more than once, keep only the row with the newest loaded_at. Order by order_id.
Expected skills
The four jobs a staging model does - rename, cast, clean, and fix the grain - and doing them in one place so no downstream model has to.
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.