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

获得积分最多的人(三)

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


全部评论

相关推荐

10-06 12:46
门头沟学院 Java
跨考小白:定时任务启动
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务