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

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

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

with t1 as(
select
    category,age_group,sum(quantity*price)total_sales_amount,sum(quantity) total_quantities
from
    sales s inner join products p 
on
    s.product_id=p.product_id inner join customer_info c
on
    s.sale_id=c.sale_id
group by
    category,age_group),t2 as(
select
    category,sum(total_sales_amount) total_sales_amount
from
    t1
group by
    category
    )

select
    t1.category product_category,age_group,t1.total_sales_amount,
    round(t1.total_sales_amount/t2.total_sales_amount,2) purchase_percentage
from
    t1 inner join t2
on
    t1.category=t2.category
order by
    product_category,age_group;
#是求总销售额的占比不是求总销售量的占比,题目有误,太恶心了,而且排序规则题目也没给清楚。

全部评论

相关推荐

06-02 15:53
阳光学院 Java
点赞 评论 收藏
分享
码农索隆:想看offer细节
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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