Beginner
Case 11 of 50
Case 011: Sales by Category
ordersproducts
Budget planning for next quarter is coming up, and the manager wants to know where to double down.
"Which product categories are actually driving revenue? I don't want to guess when we decide where next quarter's budget goes."
The data Alex is looking at
orders
| id | customer_id | product | amount | order_date |
|---|---|---|---|---|
| 101 | 1 | Keyboard | 2500 | 2026-01-05 |
| 102 | 3 | Mouse | 1200 | 2026-01-08 |
| 103 | 2 | Headphones | 3500 | 2026-01-10 |
| 104 | 4 | Monitor | 12000 | 2026-01-12 |
| 105 | 1 | Webcam | 4500 | 2026-02-03 |
| … 4 more rows | ||||
products
| id | name | category | price |
|---|---|---|---|
| 1 | Keyboard | Accessories | 2500 |
| 2 | Mouse | Accessories | 1200 |
| 3 | Headphones | Audio | 3500 |
| 4 | Monitor | Displays | 12000 |
| 5 | Webcam | Accessories | 4500 |
| … 2 more rows | |||
TASK
Help Alex answer the manager:
“Show total revenue for each 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
products.category,
SUM(orders.amount) AS category_revenue
FROM orders
JOIN products ON orders.product = products.name
GROUP BY products.category
ORDER BY category_revenue DESC;
What that query returns
Case Debrief
JOIN + GROUP BY across tables
- You can JOIN on any matching columns, not just IDs — here, product names link orders to their category.
- Combining JOIN with GROUP BY is how most real business reports get built.