学生表(学号,名字)student(sno,sname)
选课表(学号,课程号)sc(sno,cno)
课程表(课程号,课程名)course(cno,cname)
注:不是每个学生都会选课
查询选修了全部课程的学生姓名
书上的代码为
select sname
from student
where not exists
(select *
from course
where not exists
(select *
from sc
where sno=student.sno
and cno=course.cno))
选课表(学号,课程号)sc(sno,cno)
课程表(课程号,课程名)course(cno,cname)
注:不是每个学生都会选课
查询选修了全部课程的学生姓名
书上的代码为
select sname
from student
where not exists
(select *
from course
where not exists
(select *
from sc
where sno=student.sno
and cno=course.cno))
from student
where not exists --否定B条件即:不存在学生没有选择的课程,等同于选修了全部的课程的学生。
(select * from course
where not exists --B条件:作用为找出学生没有选择的课程
(select * from sc
where sno = student.sno
and cno = course.cno));