知识点

  1. 首先使用窗口函数求和建立一个新表,按照数量降序排序第一个就是所求,之后再连接user表。

代码

select u.name, t.grade_sum 
from (select user_id, sum(grade_num) over(partition by user_id ) as grade_sum 
      from grade_info 
      order by grade_sum desc 
      limit 1) as t
join user as u
on t.user_id = u.id