SELECT sno,sname FROM student s where not exists (select * from course where course.tno=(select tno from teacher where teacher.tname='叶平') and o not in (select o from course,sc where o=o and sc.sno=s.sno))
1.首先查询出叶平老师的编号:select tno from teacher where teacher.tname=‘叶平’
2.根据编号查询出叶平老师所教授的课程:select * from course where course.tno=
(select tno from teacher where teacher.tname=‘叶平’)
3.查询出每个学生所学习的课程:select o from course,sc where o=o and sc.sno=s.sno 其中sc.sno=s.sno代表相关子查询,即第一层嵌套中,查询出的学生学号与此表相连接。
4.(select * from course where course.tno=
(select tno from teacher where teacher.tname=‘叶平’)
and o not in
(select o from course,sc where o=o and sc.sno=s.sno))
此句相当于筛选出叶平老师的课程后对此学生学习的每一个课程做判断: 此课程是否不为此学生学习的课程
当此课程为此学生学习的课程时,输出假。而在完整的语句中not exists又将其置为真,则将此学生筛选出放置结果集中。
5.整条语句的思想为:双重否定即为肯定。
如果觉得《查询学过“叶平”老师所教的所有课的同学的学号 姓名》对你有帮助,请点赞、收藏,并留下你的观点哦!