select product_category,age_group,total_sales_amount,round(total_sales_amount/sum(total_sales_amount) over(partition by product_category),2) as purchase_percentage from( SELECT category AS product_category, age_group, sum(quantity * price) AS total_sales_amount FROM products p LEFT JOIN sales s ON p.product_id = s.product_id LEFT JOIN customer_info c ON s.sale_id = c.sale_id GROUP BY 1, 2 ORDER BY 1) t group by 1,2

京公网安备 11010502036488号