题解 | 商品销售排名

商品销售排名

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

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

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