题解 | 哪些产品在特定时间段内表现最为出色

哪些产品在特定时间段内表现最为出色

https://www.nowcoder.com/practice/866a4614615b43a29750537ede4bf0c8

with
    t1 as (
        select
            product_id,
            sum(sales_quantity) as total_sales_quantity,
            sum(sales_amount) as total_sales_amount
        from
            sales_records
        where
            year(sales_date) = 2024
        group by
            product_id
    ),
    t2 as (
        select
            product_id,
            total_sales_amount,
            total_sales_quantity,
            rank() over (
                order by
                    total_sales_quantity desc
            ) as ranks
        from
            t1
    )
select
    t2.product_id,
    product_name,
    total_sales_amount,
    total_sales_quantity
from
    t2
    left join products using(product_id)
where ranks=1;

全部评论

相关推荐

11-23 17:35
已编辑
济宁学院 Java
不想做程序员:面试官:蓝桥杯三等奖?你多去两次厕所都能拿二等吧
点赞 评论 收藏
分享
评论
点赞
1
分享

创作者周榜

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