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

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

其实如果不运行一遍我根本不知道还需要加where name is not null。

全部评论

相关推荐

不愿透露姓名的神秘牛友
07-04 14:23
steelhead:你回的有问题,让人感觉你就是来学习的
点赞 评论 收藏
分享
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
07-03 18:13
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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