前言:
有些查询语句比较难理解,在这里记录一下复杂查询语句的实现思路。
一、多表联查
1. 第一题:查询 李四的数学成绩
select score as 数学 from score where stuId in(select stuId from student where stuName= '李四')and courseId in(select courseId from course where courseName = '数学');
2. 第二题:查询每个学生的平均成绩// 并且降序排列
select student.stuId,student.stuName,avg(score.score) as 平均分 from student,score where student.stuId = score.stuId group by score.stuId order by avg(score.score) desc;
3. 第三条: 查询所有学生的成绩
select a.*, score.score from (select * from student full join course) as a left join score on score.courseId = a.courseId and score.stuId = a.stuId order by a.stuId,a.courseId;
未完待续。。。。。。。