使用排序函数rank()over()嵌套sum()over()解决

select u.id, u.name , a.grade
from
(select user_id , g.grade , rank()over(order by g.grade desc) r_number
from
(select user_id, sum(grade_num)over(partition by user_id) grade
from grade_info)g
group by user_id)a
join
user as u
on a.user_id = u.id
where a.r_number = 1
order by u.id asc;