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

每个商品的销售总额

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

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

全部评论

相关推荐

2025-12-22 15:04
江西农业大学 Web前端
SaviorSu:直接说下学期可以请假,一般情况学校允许我26届,大三就直接去实习了
点赞 评论 收藏
分享
2025-11-26 14:42
郑州轻工业大学 Java
在写周报的打工人很独...:这个笔试昨天晚上做了一下,真难啊,前后端,ai全有
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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