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

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

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

with temp0 as (
        select
            pi.product_id,
            sum(if(order_date between '2024-04-01' and '2024-06-30',total_amount,0)) as q2_2024_sales_total
        from product_info pi left join order_info oi on pi.product_id = oi.product_id
        group by pi.product_id
    ),
    temp1 as (
        select
            t0.product_id,
            product_name,
            q2_2024_sales_total,
            rank() over (partition by category order by q2_2024_sales_total desc ) as category_rank
        from temp0 t0 inner join product_info pi on t0.product_id = pi.product_id
    )

select
    t1.product_id,
    product_name,
    q2_2024_sales_total,
    category_rank,
    supplier_name
from temp1 t1 inner join supplier_info si on t1.product_id = si.product_id
order by t1.product_id asc;

全部评论

相关推荐

不愿透露姓名的神秘牛友
10-29 21:14
疯犬丨哈士奇:喜欢你的人会主动表白,对你有想法的人会很主动,所以要你的公司不会吊着你所以懂了吧
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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