这一道题就是接着上一道题的思路继续延伸。
主要是多了一步将lomit 0,1
所代表的最大值提取出来的过程。
select id, name, total_num
from
user
left outer join
(select user_id, sum(grade_num) as total_num
from grade_info
group by user_id
order by total_num desc) as grade
on user.id = grade.user_id
group by user.id
having total_num = (select total_num
from (select user_id, sum(grade_num) as total_num
from grade_info
group by user_id
order by total_num desc) as grade
limit 0,1)
order by user.id;