SQL查询选修了所有课程的学生姓名

select sname
from student
where not exists
(select *
from course
where not exists  
(select *
from sc
where sno =student.sno

and cno=course.cno);

 

最内部的 select * from sc where sno=student.sno and cno = course.cno是查询出所有已经选择过课程的学生及相应课程,select * from course where not exists 则是所有没有被选择的课程,

在这个基础上的 select sname from student where  not exists 则是选取所有 没有 未选择课程的学生,即选修了所有课程的学生姓名。

 

posted @ 2014-06-12 23:27  一杯半盏  阅读(1636)  评论(0编辑  收藏  举报