题解 | #获得积分最多的人(二)#
获得积分最多的人(二)
http://www.nowcoder.com/practice/b6248d075d2d4213948b2e768080dc92
- 实际分数表
- 分数累计表
- 最高分表
with grade_tmp as (
select user_id,case
when type = 'add' then grade_num
else -1*grade_num end grade
from grade_info),
highest_grade as(
select user_id,sum(grade) grade from grade_tmp
group by user_id),
highet as(
select max(grade) from highest_grade)
select user_id,name,grade from highest_grade a
left join user b
on a.user_id == b.id
where grade in highet