题解 | 对商品的销售情况进行深度分析
对商品的销售情况进行深度分析
https://www.nowcoder.com/practice/d6ced1b60af64a4998169ae717672e8e
关键:表合并;比例的计算:无需CTE子查询,用窗口函数解决分组计算
select category product_category ,age_group ,sum(quantity*price) total_sales_amount ,round(sum(quantity*price)/sum(sum(quantity*price))over(partition by category),2) purchase_percentage from sales s left join customer_info c on s.sale_id=c.sale_id left join products p on s.product_id=p.product_id group by category,age_group order by category,age_group

