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 country and revenue for paid/shipped orders, bucketing missing countries as unknown.
Result columns · in this order
countryrevenueHow to approach it
Layer paid_orders, orders_with_country, and country_revenue.
Sample input
| order_id | buyer_id | status | total_amount |
|---|---|---|---|
| 1001 | 1 | paid | 80 |
| 1004 | 1 | shipped | 220 |
| 1010 | 6 | paid | 640 |
| 1005 | 2 | paid | 540 |
| 1008 | 4 | shipped | 150 |
5 rows — all rows shown.
| customer_id | country |
|---|---|
| 1 | US |
| 2 | null |
| 3 | GB |
| 4 | IN |
| 6 | GB |
5 rows — all rows shown.
Expected output
| country | revenue |
|---|---|
| GB | 930 |
| unknown | 650 |
| US | 300 |
| IN | 150 |
4 rows — all rows shown.
Constraints
Use multiple named CTEs, join customers, group by country, and order by revenue DESC then country ASC.
Expected skills
Readable query layering, joins, and final result shaping.
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.