查询选修了全部课程的学生姓名_如何解?-MS-SQLServer/应用实例

查询选修了全部课程的学生姓名
:student 是学生表 course 是选课表 sc 是课程表
select sname
from student
where not exists
(select *
from course
where not exists  
(select *
from sc
where sno =student.sno
and cno=course.cno)
如何解释呢?我只是约约的明白,但就是给别人解释不明白。希望高手给解释一下。

------回答---------

 

------其他回答(10分)---------


select *
from course
where not exists   
(select *
from sc
where sno =student.sno
and cno=course.cno)
这一段计算得出 某学生存在没有选的课程
如果外层再加上 一个不存在 没有选的课程。那就是全选了

------其他回答(10分)---------

 

SQL code
-- 从里往外分析 select * from student -- (3) where not exists ( select * from course -- (2) where not exists ( select * from sc where sno=student.sno -- (1) and cno=course.cno ) ); -- (1) 查找某一个学生所选的所有课程 select * from sc where sno=student.sno -- (2) 查找这个学生没有选修的课程 select * from course c where not exists ( select * from sc where sno=student.sno and cno=course.cno) -- (3) 排除这个没有选修所有课程的学生
------其他回答(4分)---------


负负得正,不存在任何一科没有选修的,也就是每科都选修了

posted @ 2017-08-07 19:56  4小辣椒1  阅读(1031)  评论(0编辑  收藏  举报