Chapter 9 · Interview Level
20. Each Product's Share of Total Revenue
Medium20 XPE-Commerce
Calculate each product's share of total revenue as a percentage. Return the product name, its revenue (quantity * unit_price), and its percentage of overall revenue (rounded to 2 decimal places). Sort by revenue_pct descending.
Tables
- 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.