๐ The Budget Meeting Needs a Breakdown.
The finance team at Myntra is preparing the quarterly budget. Before allocating ad spend, they need to know what percentage of total revenue each product category contributes.
For each category, calculate total revenue (price ร quantity sold) and its percentage share of overall revenue. Round the percentage to 2 decimal places. Order by revenue descending.
This combines a JOIN, GROUP BY, and a window function (or subquery) to get the grand total for the percentage calculation.
products Table:
| Column | Type |
|---|---|
| product_id | integer |
| name | text |
| category | text |
| price | integer |
order_items Table:
| Column | Type |
|---|---|
| item_id | integer |
| order_id | integer |
| product_id | integer |
| quantity | integer |
Expected Outcome (Illustrative Sample):
| category | total_revenue | revenue_pct |
|---|---|---|
| Electronics | 127500 | 54.56 |