CODE WORKSPACE

Buyer country on each shipped order

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.

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

ordersA slice of the 12 orders. The INNER JOIN keeps only shipped orders here.
order_idbuyer_idstatustotal_amount
10034pending40
10041shipped220
10084shipped150
10106paid640
10123shipped75
customersorders.buyer_id matches customers.customer_id.
customer_idcountry
1US
3GB
4IN
6GB

Expected output

Expected outputEach shipped order joined to its buyer, ordered by order_id.
order_idtotal_amountcountry
1004220US
1008150IN
101275GB

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.

SQL
Loading...

AI evaluation

Run the SQL query to inspect preview rows.