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

获得积分最多的人(三)

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

select id
     , name
     , grade_num
  from (
        select user_id
             , sum(real_grade) as grade_num
             , DENSE_RANK() OVER(ORDER BY SUM(real_grade) DESC) AS rk
          from (
                select user_id
                     , case
                           when type='add' then grade_num
                           when type='reduce' then grade_num * (-1)
                        end as real_grade
                  from grade_info
                 ) t1
         group by user_id
        ) t2
       inner join user as u
             on u.id=t2.user_id
  where rk=1
  order by id asc
    

!!!嵌套循环

全部评论

相关推荐

不愿透露姓名的神秘牛友
10-05 10:13
已编辑
HHHHaos:让这些老登来现在秋招一下,简历都过不去
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务