早教吧作业答案频道 -->英语-->
selectsname from swhere notexists(select* fromc wherenotexists(select* fromsc wheres.sno=sc.sno andsc.c
题目详情
select sname from s where not exists
( select * from c where not exists
(select * from sc where s.sno=sc.sno and sc.cno=c.cno));
原题是这样的:Find the students who take all the courses and list their names.(相当于查询这样的学生,没有一门课是他不选的)
上面的是答案,但是不知道not exists怎么理解
( select * from c where not exists
(select * from sc where s.sno=sc.sno and sc.cno=c.cno));
原题是这样的:Find the students who take all the courses and list their names.(相当于查询这样的学生,没有一门课是他不选的)
上面的是答案,但是不知道not exists怎么理解
▼优质解答
答案和解析
exists 与 not exists存在谓词,判断并返回布尔类型结果.
select sname from s
where not exists (select * from c where not exists (select * from sc where s.sno=sc.sno and sc.cno=c.cno));
下面这句你把where后面的连接条件去掉理解就是选了课的所有课号和学号,
select * from sc where s.sno=sc.sno and sc.cno=c.cno
下面这句把WHERE 后面的SNO的连接条件去掉理解就是
没有被选的课程信息
select * from c where not exists (select * from sc where s.sno=sc.sno and sc.cno=c.cno));
因为这个关系模式牵扯到三个表,整个代码中的WHERE都是连接条件,你不要在这里钻牛角尖.
整个句子是这个意思,
S表不存在这样的人(姓名),他的学号在SC表里出现,他的SC表的课号没有在C表出现.
换个角度理解就是这个学号的SC表的课号全部在C表出现了,那么这个学号就是选了所有课的学号,根据学号,又能从S表获得姓名.
两个否定逻辑判断推出肯定的学生姓名.
select sname from s
where not exists (select * from c where not exists (select * from sc where s.sno=sc.sno and sc.cno=c.cno));
下面这句你把where后面的连接条件去掉理解就是选了课的所有课号和学号,
select * from sc where s.sno=sc.sno and sc.cno=c.cno
下面这句把WHERE 后面的SNO的连接条件去掉理解就是
没有被选的课程信息
select * from c where not exists (select * from sc where s.sno=sc.sno and sc.cno=c.cno));
因为这个关系模式牵扯到三个表,整个代码中的WHERE都是连接条件,你不要在这里钻牛角尖.
整个句子是这个意思,
S表不存在这样的人(姓名),他的学号在SC表里出现,他的SC表的课号没有在C表出现.
换个角度理解就是这个学号的SC表的课号全部在C表出现了,那么这个学号就是选了所有课的学号,根据学号,又能从S表获得姓名.
两个否定逻辑判断推出肯定的学生姓名.
看了 selectsname ...的网友还看了以下:
在SOL语言的SELECT语句中,实现分组操作的是( )子句。A) group by B) from 2020-05-23 …
在SQL语言的SELECT语句中,实现分组操作的是( )子句。A)group byB)fromC)w 2020-05-23 …
在SQL语言的SELECT语句中,实现投影操作的是哪个子句?A.SELECTB.FROMC.WHER 2020-05-23 …
在SQL的SELECT语句中,实现投影操作的是______子句。A.SELECTB.FROMC.WH 2020-05-23 …
在SQL语言的SELECT语句中,实现投影操作的是哪个子句?A.SelectB.FromC.Wher 2020-05-23 …
在SQL语言的SELECT语句中,实现投影操作的是哪个子句?A.SELECTB.FROMC.WEHE 2020-05-23 …
在SQL语言的SELECT语句中,实现投影操作的是哪一个子句?A.selectB.fromC.whe 2020-05-23 …
在SQL的SELECT语句中,实现投影操作的是子句()。A.SELECTB.FROMC.WHERED 2020-05-24 …
在SQL语言的SELECT语句中,对投影操作进行说明的是哪个子句?()A) SELECTB) FRO 2020-05-24 …
selectsname from swhere notexists(select* f 2020-06-14 …