SQL查询选修了全部课程的学生姓名查询选修了全部课程的学生姓名:student 是学生表 course 是选课表 sc 是课程表select snamefrom studentwhere not exists(select *from coursewhere not exists (select *from scwhere sn

来源:学生作业帮助网 编辑:作业帮 时间:2024/05/04 00:06:34
SQL查询选修了全部课程的学生姓名查询选修了全部课程的学生姓名:student 是学生表 course 是选课表 sc 是课程表select snamefrom studentwhere not exists(select *from coursewhere not exists  (select *from scwhere sn

SQL查询选修了全部课程的学生姓名查询选修了全部课程的学生姓名:student 是学生表 course 是选课表 sc 是课程表select snamefrom studentwhere not exists(select *from coursewhere not exists (select *from scwhere sn
SQL查询选修了全部课程的学生姓名
查询选修了全部课程的学生姓名
: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)
select *
from course
where not exists
(select *
from sc
where sno =student.sno
and cno=course.cno)
这一段计算为什么就得出 某学生存在没有选的课程?

SQL查询选修了全部课程的学生姓名查询选修了全部课程的学生姓名:student 是学生表 course 是选课表 sc 是课程表select snamefrom studentwhere not exists(select *from coursewhere not exists (select *from scwhere sn
第一问:两个NOT EXISTS表示双重否定:没有一个选了课的学生没有选course表里的课程
select sname
from student
where not exists /*没有一个学生满足以下条件*/
(select * from course
where not exists /*什么条件呢?没有选过Course表里的课*/
(select * from sc
where sno =student.sno /*这里两个=分别指对应的关系,表示选过课并且是Course里and cno=course.cno) 的课,只不过用not exists否定掉了*/
第二问:其实和NOT IN 是一个意思 exists只返回true 或false 这里not exists里的内容 其实就是指学生选过的课程,再用NOT EXISTS否定了,就变成了没有选的