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
| id | name | country |
|---|---|---|
| 1 | Sam | Germany |
| 2 | Nina | Canada |
| 3 | David | Germany |
| 4 | Maya | Japan |
| 5 | Daniel | Canada |
| … 5 more rows | ||
orders
| id | customer_id | order_date |
|---|---|---|
| 101 | 1 | 2026-01-05 |
| 102 | 2 | 2026-01-08 |
| 103 | 3 | 2026-01-12 |
| 104 | 1 | 2026-01-20 |
| 105 | 4 | 2026-02-01 |
| … 23 more rows | ||
order_items
| order_id | product_id | quantity |
|---|---|---|
| 101 | 1 | 2 |
| 101 | 2 | 1 |
| 102 | 3 | 1 |
| 103 | 2 | 3 |
| 104 | 5 | 1 |
| … 29 more rows | ||
products
| id | name | category | price |
|---|---|---|---|
| 1 | Keyboard | Accessories | 2500 |
| 2 | Mouse | Accessories | 1200 |
| 3 | Headphones | Audio | 3500 |
| 4 | Monitor | Displays | 12000 |
| 5 | Laptop | Computers | 60000 |
| … 5 more rows | |||
TASK
Help Alex answer the manager:
“Show total revenue for every combination of customer country and product category.”
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.