题解 | 对商品的销售情况进行深度分析

对商品的销售情况进行深度分析

https://www.nowcoder.com/practice/d6ced1b60af64a4998169ae717672e8e

with t as (
    select category, age_group, sum(quantity*price) as total_sales_amount
    from products a
    join sales b on a.product_id=b.product_id
    join customer_info c on b.sale_id=c.sale_id
    group by category, age_group
), t1 as (
    select category, sum(total_sales_amount) as sum_total_sales_amount
    from t
    group by category
)
select t.category as product_category, t.age_group, total_sales_amount,
       round(t.total_sales_amount/t1.sum_total_sales_amount, 2) as purchase_percentage
from t join t1 on t.category=t1.category
order by t.category, age_group

全部评论

相关推荐

01-30 16:13
浙江大学 Java
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务