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

select
    a.name product_name,
    a.total_sales,
    rank() over (
        partition by
            a.category
        order by
            total_sales desc
    ) category_rank
from
    (
        select
            name,
            category,
            sum(quantity) total_sales
        from
            test.products pr
            join test.orders ord on pr.product_id = ord.product_id
        group by
            name,
            category
    ) a

全部评论

相关推荐

评论
1
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务