题解 | 商品销售排名

商品销售排名

https://www.nowcoder.com/practice/79c6c3d6d66946f79387bca73c0a29f4

select
    t.product_name,
    t.sales
from
    (select
        aa.product_name,
        aa.price * aa.cnt as sales,
        row_number() over(order by aa.price * aa.cnt desc) as rk
    from
        (select
            b.product_name,
            b.price,
            count(distinct a.trace_id) as cnt
        from
            user_client_log a
        left join
            product_info b on a.product_id = b.product_id
        where   
            a.step = 'select' and a.pay_method is not null
        group by 
            1,2) aa) t
where 
    t.rk <= 2

全部评论

相关推荐

牛至超人:把哈工大,再加大加粗,看见闪闪发光的哈工大字样,面试官直接流口水
投递字节跳动等公司6个岗位
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
12-17 17:40
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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