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 order_id, order_total, items_total, and diff (order_total - items_total) for orders whose stored total differs from the recomputed line-item total. Order by order_id.
Result columns · in this order
order_idorder_totalitems_totaldiffHow to approach it
Aggregate line items in a CTE, join to orders, and filter to the rows where the two totals disagree.
Sample input
| order_id | total_amount |
|---|---|
| 1001 | 80 |
| 1002 | 120 |
| 1007 | 95 |
| 1008 | 150 |
4 rows — all rows shown.
| order_id | quantity | unit_price |
|---|---|---|
| 1001 | 1 | 80 |
| 1001 | 2 | 15 |
| 1001 | 1 | 120 |
| 1007 | 1 | 15 |
| 1008 | 5 | 20 |
5 rows — all rows shown.
Expected output
| order_id | order_total | items_total | diff |
|---|---|---|---|
| 1001 | 80 | 230 | -150 |
| 1002 | 120 | 140 | -20 |
| 1007 | 95 | 15 | 80 |
| 1008 | 150 | 180 | -30 |
4 rows — all rows shown.
Constraints
Recompute SUM(quantity * unit_price) per order in a CTE, JOIN it to orders, and keep only rows where total_amount <> items_total. Include the signed diff column.
Expected skills
Reconciliation by independent recomputation and surfacing signed differences.
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.