select sname
from student
where not exists
(select *
from course
where not exists
(select *
from sc
where sno=student.sno
and cno=course.cno))
麻烦帮我解释一下每一个not exists的含义
加了not就代表相反,就是不存在的意思
你的父查询的结果中不能包含子查询里查出的结果。不包含的意思。(我也是略懂)
not exists就是不存在的意思。
你从最里面的括号看起,先是查询得到几组数据。然后看外面的第二层,也就是course中不是你前面查询得到的几组数据作为这一层的数据。然后到最外面一层
也就是第一个not exists,select sname from student where not exists(上一层的数据)。
也就是从student中查询sname的数据不是上一层查询得到的数据的某个。
你可以把这条语句分开写,然后再一条一条的执行,你就能看见效果了。别人说的你也是听不懂的。
第一条select * from sc where sno=student.sno and cno=course.cno
第二条select * from course where not exists 第一条的数据
第三条select sname from student where not exists 第二条的数据
赞同楼上的意见,关于数据库的优化问题,请访问http://www.data.5helpyou.com/,希望能给你提供帮助