Beginner Case 13 of 50

Case 013: Revenue by Country and Category

customersordersorder_itemsproducts

Leadership is deciding which product categories to push in which markets, and a single-dimension report won't cut it. The manager passes along their ask.

"Not just revenue by country. Not just revenue by category — could you cross the two together for me? I need to see what actually sells where."

The data Alex is looking at

customers
idnamecountry
1SamGermany
2NinaCanada
3DavidGermany
4MayaJapan
5DanielCanada
… 5 more rows
orders
idcustomer_idorder_date
10112026-01-05
10222026-01-08
10332026-01-12
10412026-01-20
10542026-02-01
… 23 more rows
order_items
order_idproduct_idquantity
10112
10121
10231
10323
10451
… 29 more rows
products
idnamecategoryprice
1KeyboardAccessories2500
2MouseAccessories1200
3HeadphonesAudio3500
4MonitorDisplays12000
5LaptopComputers60000
… 5 more rows
TASK

Help Alex answer the manager:

“Show total revenue for every combination of customer country and product category.”
SQL editor Ctrl+Enter to run
Write a query above and hit Run to see what comes back.
No hints requested yet — click "Get a hint" when you're stuck.
Alex's final query — this is for reference. Copy it into your own thinking, not into the editor above.
SELECT customers.country, products.category, SUM(order_items.quantity * products.price) AS revenue FROM customers JOIN orders ON orders.customer_id = customers.id JOIN order_items ON order_items.order_id = orders.id JOIN products ON products.id = order_items.product_id GROUP BY customers.country, products.category ORDER BY customers.country, revenue DESC;
What that query returns
Case Debrief Multi-column GROUP BY
  • GROUP BY can take more than one column — GROUP BY customers.country, products.category groups by every unique pairing of the two, not just one or the other.
  • That's why the result has a separate row for "Canada + Accessories", another for "Canada + Computers", and so on — one row per combination that actually happened, instead of one row per country or one row per category alone.

Case closed.

Ready for the next one?

Next: Case 014 — Small, Medium, or Large →