Chapter 8 · Window Functions
06. Category Share of Total Revenue
Medium20 XPE-Commerce
Calculate each category's share of total revenue as a percentage. For each category, show the category name, category revenue (from order_items: quantity * unit_price), and the percentage of overall revenue that category represents. Round percentages to 1 decimal place. Sort by percentage descending.
Tables
- PKidINT
- nameTEXT
- descriptionTEXT
- PKidINT
- nameTEXT
- FKcategory_id→ categories.idINT
- priceREAL
- costREAL
- stock_quantityINT
- created_atTIMESTAMP
- PKidINT
- FKorder_id→ orders.idINT
- FKproduct_id→ products.idINT
- quantityINT
- unit_priceREAL
- discountREAL
Need help?
Ask Sol
AI tutor — looks at your current query and nudges you, without spoiling the answer.
Solution
Try the hints first — solving it yourself is what makes it stick.