题解 | 分析每个商品在不同时间段的销售情况

分析每个商品在不同时间段的销售情况

https://www.nowcoder.com/practice/eec7a93e1ab24233bd244e04e910d2f9

with zw as (
select
p.product_id,
p.product_name,
p.category,
date_format(o.order_date,'%Y-%m') as date,
ifnull(o.total_amount,0.00) as total_amount
from product_info p 
left join order_info o 
on p.product_id = o.product_id and date_format(o.order_date,'%Y-%m') in ('2024-04','2024-05','2024-06')
)
select 
zw.product_id,
zw.product_name,
sum(zw.total_amount) as q2_2024_sales_total,
row_number() over(partition by category order by sum(total_amount) desc) as category_rank,
su.supplier_name
from zw left join supplier_info su 
on zw.product_id = su.product_id
group by zw.product_id,zw.product_name,zw.category,su.supplier_name
order by zw.product_id;

全部评论

相关推荐

不愿透露姓名的神秘牛友
01-07 00:20
点赞 评论 收藏
分享
烤点老白薯:亲娘嘞🐶💩啊你的简历
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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