学生表(学号,名字)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))
看不懂,两个否定不就肯定了,越看越乱,不知怎么运行的???
请大虾指点
abingpow 所写的那段代码,运行后结果不对。看来理解的也不对
书上的思路是==等价于:没有一门课程是这个学生不选的
但是代码的各步运行还是不明白
sql语言中两个not exists 的疑问
答案:2 悬赏:60
解决时间 2021-01-03 22:08
- 提问者网友:无依无靠的距离
- 2021-01-03 18:20
最佳答案
- 二级知识专家网友:修女的自白
- 2021-01-03 19:07
等同于
select student.sname from student,course,sc where sc.sno<>student.sno and sc.cno<>course.cno
select student.sname from student,course,sc where sc.sno<>student.sno and sc.cno<>course.cno
全部回答
- 1楼网友:兮沫♡晨曦
- 2021-01-03 19:34
in 和not in 是把外表和那表作hash join;
而exists 和 not exists 是对外表作loop,每次loop再对那表进行查询。
所以,in适合内外表都很大的情况,exists适合外表结果集很小的情况。
我要举报
如以上问答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯