现有如下2个表,根据要求写出SQL语句。
student表:编号(sid),姓名(sname),性别(sex)
course表:编号(sid),科目(subject),成绩(score)
问题1:查询出所有科目总成绩最高的学生姓名及总成绩
方式一):
1 select s.sid,s.sname,sum(c.score) as z 2 from course c 3 left join student s 4 on c.sid = s.sid 5 group by c.sid,s.sname 6 order by z desc 7 limit 1
方式二):
1 SELECT 2 sname 3 FROM 4 student 5 WHERE 6 sid IN ( 7 SELECT 8 sid 9 FROM 10 ( 11 SELECT 12 sid, 13 sum(score) AS z 14 FROM 15 grade 16 GROUP BY 17 sid 18 ORDER BY 19 z DESC 20 LIMIT 1 21 ) AS qw 22 ) 23 UNION 24 ( 25 SELECT 26 sum(score) AS z 27 FROM 28 grade 29 GROUP BY 30 sid 31 ORDER BY 32 z DESC 33 LIMIT 1 34 )