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

Posted 4小辣椒1

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了查询选修了全部课程的学生姓名_如何解?-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分)---------


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























以上是关于查询选修了全部课程的学生姓名_如何解?-MS-SQLServer/应用实例的主要内容,如果未能解决你的问题,请参考以下文章

数据库SQL语句中 查询选修了全部课程的学生的学号和姓名 理解

查询选修了全部课程的学生姓名转

查询选修了全部课程的学生姓名

SQL中,查询学生姓名及所选修的课程名和成绩

在SQL中,如何查询至少选修了两门课程的学生学号呢?

查询选修了java课程的学生的姓名怎么操作?