Revenue per category
Mediumrow order matters
Show each product category and its revenue (sum of quantity × unit_price over all order items), highest first.
Tables: customers(customer_id, name, city, country, joined) · products(product_id, name, category, price) · orders(order_id, customer_id, order_date, status) · order_items(order_id, product_id, quantity, unit_price)
Your query✔ Solved
Show the expected result
| category | revenue |
|---|---|
| Electronics | 11502.0 |
| Furniture | 8153.0 |
| Books | 2638.0 |
| Grocery | 824.0 |
| Stationery | 339.0 |
5 rows
Show a solution
SELECT p.category, SUM(i.quantity * i.unit_price) AS revenue FROM order_items i JOIN products p ON p.product_id = i.product_id GROUP BY p.category ORDER BY revenue DESC;
SQL used
New to SQL? The free SQL course teaches everything these problems use, with a self-checking exercise in every lesson.