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

每个商品的销售总额

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

select t3.product_name,t3.total_sales,rank()over(partition by t3.category order by t3.total_sales desc) as category_rank
from(
    select t2.name as product_name, sum(t1.quantity) as total_sales,t2.category as category,t1.product_id as product_id 
    from orders as t1
    left join products as t2 using(product_id)
    group by t1.product_id
) as t3
where product_name is not null
order by t3.category asc,t3.total_sales desc,t3.product_id asc

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

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