使用窗口函数sum()over()来解答

  • 虽然但是,我觉得是有点歧义的,他问题应该问成:总积分最高的 而不是 增加积分最高的
select u.name, g.grade
from
(select user_id, sum(grade_num)over(partition by user_id) grade
from grade_info
order by grade desc
limit 1)g
join
user as u
on g.user_id = u.id