题解 | #获得积分最多的人(三)#
获得积分最多的人(三)
http://www.nowcoder.com/practice/d2b7e2a305a7499fb310dc82a43820e8
with t as ( select distinct id, name, sum(grade_num*type)over(partition by id) g from (select grade_info.user_id id, user.name name, grade_info.grade_num grade_num, case when type='add' then 1 else -1 end type from grade_info left join user on grade_info.user_id=user.id) s) select id, name, g from t where g=(select max(g) from t) order by id