Problems / Cumulative Sales Percentage / Editorial
This problem combines two window function patterns:
SUM(sales_amount) OVER (PARTITION BY category) — no ORDER BY means the frame spans the entire partition, giving the category total on every row.
SUM(sales_amount) OVER (PARTITION BY category)
SUM(sales_amount) OVER (PARTITION BY category ORDER BY sales_amount DESC) — with ORDER BY, the default frame is RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW, producing a running total.
SUM(sales_amount) OVER (PARTITION BY category ORDER BY sales_amount DESC)
RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW
Divide the cumulative sum by the partition total. Use 100.0 * to force float division, and ROUND(..., 2) for clean output.
100.0 *
ROUND(..., 2)
Cumulative percentage analysis (Pareto analysis) helps identify which products contribute most to category revenue — the classic 80/20 rule.
Solve Cumulative Sales Percentage yourself →