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

每个商品的销售总额

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

select
    t2.name product_name,
    t2.total_sales,
    t2.category_rank
from
    (
        select
            p.name,
            p.category,
            t1.quantity total_sales,
            rank() over (
                partition by
                    p.category
                order by
                    t1.quantity desc,
                    t1.product_id
            ) category_rank
        from
            (
                select
                    product_id,
                    sum(quantity) quantity
                from
                    orders
                group by
                    product_id
            ) t1,
            products p
        where
            t1.product_id = p.product_id
    ) t2
order by
    t2.category,
    t2.total_sales desc;

全部评论

相关推荐

白火同学:能。我当初应届沟通了1200,收简历50,面试10左右吧,加油投吧
点赞 评论 收藏
分享
04-17 10:16
门头沟学院 Java
小浪_coder:24届很难找了,马上25的都毕业了还有很多没找到的
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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