题解 | 每个商品的销售总额

每个商品的销售总额

https://www.nowcoder.com/practice/6d796e885ee44a9cb599f47b16a02ea4

with
t1 as(
    select distinct
        product_id,
        name,
        sum(quantity)over(partition by name order by name) as pcount,
        category
    from
        orders left join products using(product_id)
)
,t2 as(
    select
        product_id,
        name as product_name,
        pcount as total_sales,
        rank()over(partition by category order by pcount desc) as category_rank
    from
        t1
)

select product_name,total_sales,category_rank from t2 where product_name is not null

全部评论

相关推荐

点赞 评论 收藏
分享
10-22 19:44
门头沟学院 Java
面了100年面试不知...:那我得去剪个头
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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