题解 | #获得积分最多的人(三)#
获得积分最多的人(三)
http://www.nowcoder.com/practice/d2b7e2a305a7499fb310dc82a43820e8
with t1 as ( select user_id,case when type='reduce' then -grade_num else grade_num end as grade_num from grade_info ), total as( select a.id,name,sum(grade_num) over(partition by name)as grade_sum from user a left join t1 b on a.id=b.user_id order by grade_sum desc ) select id,name,grade_sum from total where grade_sum in( select max(grade_sum) from total ) group by id order by id