我个人的理解,可能表达不是很准确. 前面3行大概分别定义一个常量集合; 后面是一个SQL查询语句,条件中是嵌套的判断条件, not exists 是指不存在于你后面的集合
用了兩個exists就是反兩次了。 就是查詢學了全部課程學生的姓名了。
(select * from c where not exists (select * from sc where sc.c#=c.c#)) --查询C中有,而sc中没有的记录 ,把这个集合叫做D吧 加上 s(s#,sname,age,sex) sc(s#,c#,grade) c(c#,cname,teacher) select sname from s where not exists (select * from c where not exists (select * from sc where sc.s#=s.s# and sc.c#=c.c#))--则是查询S中有,而D中没有的记录!(关键:你的对应条件是否唯一)
前面3行大概分别定义一个常量集合;
后面是一个SQL查询语句,条件中是嵌套的判断条件,
not exists 是指不存在于你后面的集合
就是查詢學了全部課程學生的姓名了。
(select *
from c
where not exists
(select *
from sc
where
sc.c#=c.c#))
--查询C中有,而sc中没有的记录 ,把这个集合叫做D吧
加上
s(s#,sname,age,sex)
sc(s#,c#,grade)
c(c#,cname,teacher)
select sname
from s
where not exists
(select *
from c
where not exists
(select *
from sc
where sc.s#=s.s#
and sc.c#=c.c#))--则是查询S中有,而D中没有的记录!(关键:你的对应条件是否唯一)