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

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

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

with
    t1 as (
        select distinct
            product_id,
            product_name,
            sum(total_amount) over (
                partition by
                    product_info.product_id
            ) as q2_2024_sales_total,
            category
        from
            product_info
            left join order_info using (product_id)
        where
            order_info.order_date between '2024-04-01' and '2024-06-30'
    )
select
    product_id,
    product_name,
    q2_2024_sales_total,
    rank() over (
        partition by
            category
        order by
            q2_2024_sales_total desc
    ) as category_rank,
    supplier_name
from
    (
        select distinct
            supplier_info.product_id,
            product_info.product_name,
            ifnull(q2_2024_sales_total, 0) as q2_2024_sales_total,
            product_info.category,
            supplier_info.supplier_name
        from
            supplier_info
            left join product_info using (product_id)
            left join t1 using (product_id)
    ) as t2
order by product_id;

写了挺久的,思路不难,难在磨

全部评论

相关推荐

金俊涛:实习经历太简短了,丰富一些,实习还是很重要的,你好歹写点平常干什么,让hr有的问
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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