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

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

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

with
    t as (
        select
            product_id,
            product_name,
            sum(total_amount) as q2_2024_sales_total,
            category
        from
            order_info
            join product_info using(product_id)
        where
            order_date between '2024-04-01' and '2024-06-30'
        group by
            product_id,
            product_name
    )
select
    product_id,
    product_name,
    case
        when q2_2024_sales_total is null then 0
        else q2_2024_sales_total
    end as q2_2024_sales_total,
    
    rank() over (
        partition by
            category
        order by
            q2_2024_sales_total DESC
    ) as category_rank,
    supplier_name
from
    product_info
    join supplier_info using(product_id)
    left join t using (product_id, product_name, category)
order by product_id      

全部评论

相关推荐

11-03 18:50
门头沟学院 Java
迷茫的大四🐶:问就是马上到,一周五天,6个月以上,全国可飞
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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