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

每个商品的销售总额

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

select
    t.product_name,
    t.total_sales,
    dense_rank() over(partition by t.category order by t.total_sales desc) as category_rank
from
    (select
        p.name as product_name,
        p.category,
        p.product_id,
        sum(o.quantity) as total_sales
    from 
        products p
    left join
        orders o on o.product_id = p.product_id
    group by 
        1,2,3
    having total_sales is not null) t
order by 
    t.category,t.total_sales desc

全部评论

相关推荐

点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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