题解 | #获得积分最多的人(三)#

获得积分最多的人(三)

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

with
    t1 as (
        select
            b.user_id,b.type type ,
            grade_num - coalesce(
                lead (grade_num, 1) over (
                    partition by
                        user_id
                    order by
                        type
                ),
                0
            ) num
        from
            (
                select
                    user_id,
                    type,
                    sum(grade_num) grade_num
                from
                    grade_info a
                group by
                    user_id,
                    type
            ) b
    )
        
        select c.id,d.name,c.grade_num
        from
        (
        select
            t1.user_id id,
            t1.num grade_num,
            rank() over( order by t1.num desc) rn
        from t1 
        where t1.type='add'
        )c
        left join user d
        on c.id=d.id
        where c.rn=1
        order by c.id


全部评论

相关推荐

感性的干饭人在线蹲牛友:🐮 应该是在嘉定这边叭,禾赛大楼挺好看的
点赞 评论 收藏
分享
三年之期已到我的offer快到碗里来:9硕都比不上9本
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务