题解 | #获得积分最多的人(二)#
获得积分最多的人(二)
http://www.nowcoder.com/practice/b6248d075d2d4213948b2e768080dc92
select distinct p.id, p.name,p.grade_sum
from
(select u.id,u.name,sum(grade_num) over (partition by user_id) as grade_sum
from user as u
inner join
grade_info as g
on u.id=g.user_id
order by grade_sum desc) as p
where p.grade_sum=
(select max(p.grade_sum)
from
(select u.id,u.name,sum(grade_num) over (partition by user_id) as grade_sum
from user as u
inner join grade_info as g
on u.id=g.user_id
order by grade_sum desc) as p)
写的好复杂,不过思路还是找到最大值,希望有大神能指点一下简化方法