with tmp_table as ( select t1.id, t1.name, sum(t2.grade_num) as grade_sum from user as t1 join grade_info as t2 on t1.id = t2.user_id group by t1.id ) select id, name, grade_sum from tmp_table where grade_sum = (select max(grade_sum) from tmp_table) order by id;