题解 | #获得积分最多的人(三)#
获得积分最多的人(三)
http://www.nowcoder.com/practice/d2b7e2a305a7499fb310dc82a43820e8
Select b.user_id, user.name, b.grade_sum
From
(Select a.user_id, a.grade_sum, rank()over(order by grade_sum desc) as r
From
(Select user_id,
sum(case when type='add' then grade_num else (-1)*grade_num end) as grade_sum
From grade_info
Group By user_id) as a)as b Join user ON b.user_id=user.id
Where b.r=1