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
Build a CTE for paid/shipped orders, then aggregate revenue by buyer.
Result columns · in this order
buyer_idrevenueHow to approach it
Start with paid_orders, then aggregate buyer_revenue.
Sample input
| order_id | buyer_id | status | total_amount |
|---|---|---|---|
| 1001 | 1 | paid | 80 |
| 1004 | 1 | shipped | 220 |
| 1009 | 1 | pending | 30 |
| 1005 | 2 | paid | 540 |
| 1010 | 6 | paid | 640 |
5 rows — all rows shown.
Expected output
| buyer_id | revenue |
|---|---|
| 2 | 650 |
| 6 | 640 |
| 1 | 300 |
| 3 | 290 |
| 4 | 150 |
5 rows — all rows shown.
Constraints
Use at least one CTE. Return buyer_id and revenue ordered by revenue descending, then buyer_id.
Expected skills
CTE decomposition, grouped aggregation, and readable intermediate naming.
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.