Practice · easy · dataset: ecom
Revenue by category
Finance wants to know which product categories bring in the most money. For each category, add up the value of every line item that has been ordered.
Return two columns: category and revenue, where revenue is the sum of quantity * unit_price
across all order items for products in that category, rounded to two decimals. Sort by revenue from
highest to lowest, and break ties by category ascending.
Tables available
| Table | Columns |
|---|---|
products |
product_id, name, category, unit_price |
order_items |
order_id, product_id, quantity, unit_price |
Use the unit_price recorded on the line item, not the current catalog price: prices can change
between orders. Count every line item regardless of the parent order’s status.
⌘/Ctrl + Enter to grade
Write a query, then grade it.
Hints
Try it first. Reveal a hint only when you are stuck.