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
You are writing the is_incremental() branch of a dbt model. Return order_id, buyer_id, status, total_amount and updated_at from orders_raw for every row the last run could have missed. stg_orders is the model's existing table - dbt's {{ this }}. Order by order_id.
Result columns · in this order
order_id | Stable order identifier. |
buyer_id | Customer who placed the order. |
status | Status as at the last load. |
total_amount | Order value as at the last load. |
updated_at | The high-water mark you are filtering against. |
How to approach it
The obvious filter is updated_at > (SELECT MAX(updated_at) FROM stg_orders). Run it, count the rows, then look at order 5004 and ask why it never arrives.
Sample input
| order_id | buyer_id | status | total_amount | updated_at |
|---|---|---|---|---|
| 5000 | 41 | paid | 120 | 2026-03-01 10:00:00 |
| 5001 | 42 | paid | 240 | 2026-03-05 20:00:00 |
| 5002 | 43 | paid | 90 | 2026-03-05 22:00:00 |
| 5003 | 44 | pending | 310 | 2026-03-06 09:15:00 |
| 5004 | 45 | paid | 175 | 2026-03-05 21:40:00 |
5 rows — all rows shown.
| order_id | buyer_id | status | total_amount | updated_at |
|---|---|---|---|---|
| 5000 | 41 | paid | 120 | 2026-03-01 10:00:00 |
| 5001 | 42 | paid | 240 | 2026-03-05 20:00:00 |
| 5002 | 43 | paid | 90 | 2026-03-05 22:00:00 |
3 rows — all rows shown.
Expected output
| order_id | buyer_id | status | total_amount | updated_at |
|---|---|---|---|---|
| 5001 | 42 | paid | 240 | 2026-03-05 20:00:00 |
| 5002 | 43 | paid | 90 | 2026-03-05 22:00:00 |
| 5003 | 44 | pending | 310 | 2026-03-06 09:15:00 |
| 5004 | 45 | paid | 175 | 2026-03-05 21:40:00 |
4 rows — all rows shown.
Constraints
Filter orders_raw against the newest updated_at already in stg_orders, less a one-day lookback window. Handle the first run, when stg_orders is empty, so the model still builds. Order by order_id.
Expected skills
Watermark selection, why a lookback window is needed at all, and keeping the first run working when the target table has no rows yet.
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.