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 o.order_id, o.total_amount, and c.country for orders whose status is shipped, joining orders to customers on the buyer. Order by order_id.
Result columns · in this order
order_id | Order identifier; unique in this table. |
total_amount | Order total in dollars. |
country | Customer country. Can be NULL when unknown. |
How to approach it
JOIN orders AS o to customers AS c ON c.customer_id = o.buyer_id, filter status = 'shipped', then ORDER BY o.order_id.
Sample input
| order_id | buyer_id | status | total_amount |
|---|---|---|---|
| 1003 | 4 | pending | 40 |
| 1004 | 1 | shipped | 220 |
| 1008 | 4 | shipped | 150 |
| 1010 | 6 | paid | 640 |
| 1012 | 3 | shipped | 75 |
5 rows — all rows shown.
| customer_id | country |
|---|---|
| 1 | US |
| 3 | GB |
| 4 | IN |
| 6 | GB |
4 rows — all rows shown.
Expected output
| order_id | total_amount | country |
|---|---|---|
| 1004 | 220 | US |
| 1008 | 150 | IN |
| 1012 | 75 | GB |
3 rows — all rows shown.
Constraints
Join orders to customers on customers.customer_id = orders.buyer_id. Keep only status = 'shipped'. Alias the tables (o, c) and select the three named columns.
Expected skills
Writing an INNER JOIN, expressing the match in ON, and aliasing tables for readable column references.
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.