当前位置:首页 » 操作系统 » 数据库notexists

数据库notexists

发布时间: 2022-10-20 14:45:01

㈠ 怎么理解数据库中not exist

not exists 是取反逻辑,也就是里面查询没有结果集就是为真,如果有结果集就是为假。然后作为整体的条件拼接到着查询上

㈡ 数据库语言 not exists 是什么意思

就是不在这个范围的意思
select id
from table
where name not exists(select 1
from table
where name = 'aaa')
也许你看不懂这个1的意思,不过在使用EXISTS的时候,通常都会使用1,它代表所查询出来的集合,等同于select name。
整个例子的意思是:查询name不等于aaa的所有ID。
不明白再问我,谢谢!

㈢ 数据库语言关于not exist的用法

卤煮你好,
答案写法很好,我看了很久才弄明白,但我认为有漏洞,实际应用的话应该需要完善
我先说我的写法,再解释答案的逻辑
我的:
select st.sno, st.sname
FROM student st
where exists(
select 1 from SC a join Cource b on a.Cno=b.Cno where a.Sno=st.Sno and
a.Cno in(3,5,8) having count(*)=3
)
或者
select st.sno, st.sname
FROM student st
where exists(
select 1 from SC where Sno=st.Sno and
Cno in(3,5,8) having count(*)=3
)
/*通过和上面的比较你可以发现其实Cource其实没有作用,但是第一种写法更加严密,因为可以判断SC中的Cno是不是有效的*/
-------分割线--------------------------
再来看看这个答案
SELECT student.sno, student.sname
FROM student
WHERE not exists(select course.cno
from course
where course.cno in (3,5,8) and not exists(select *
from sc
where student.sno=sc.sno and course.cno=sc.cno));
看起来很复杂,我们先来拆分下
因为sql 的查询和执行是逐条进行的,主体是从Student表中中选数据,我们假设Student中有【小明】这个人,如何判断小明是不是该出来呢,只要
select course.cno
from course
where course.cno in (3,5,8) and not exists(select *
from sc
where ‘小明’=sc.sno and course.cno=sc.cno)
这一大坨【不返回结果】即可,
这一坨
,select course.cno
from course
where course.cno in (3,5,8) and not exists(select *
from sc
where ‘小明’=sc.sno and course.cno=sc.cno)
意思就比较明确了(我这儿迷糊了好一阵子)
只要小明同时选修了3,5,8那么这段话就不返回结果,所以最终小明就出现了!

/*ps.题目有个地方我没太看明白,“3且5且8” 是指的是同时选修3,5,8呢还是同时选修3,5,8且只选修这三个。如果是后者这3个写法还要再加一句exists*/
----三段写法全部测试通过,卤煮可以尽情测试~要给分啊!!!!!!!!!!!!

㈣ oracle中not exists 是什么意思

not exists就是检测有没有符合条件的记录的意思。
一般放到where后面,检测子查询的结果。

㈤ sql中not exists用法

恩,对的,其实写法很多

1、
select id from a where id not in (select id_no from b)

2、
select id from a
except
select id_no from b

㈥ mysql数据库,not exists 语句

在sql语言里"存在"exists子句是非常不好理解的。

exists子句有两种用法,一种为独立exists子查询,另一种是父子关联子查询。前者对父查询不构成筛选作用,子查询若果有记录存在的话则输出所有的父查询记录集,反之则父查询输出空记录集。后者会对父查询构成筛选作用,不使用not关键字的情况下输出父查询中与子查询的交集,而使用not时则输出父查询中与子查询的非交集。至于如何判断exists子查询属于独立还是父子关联查询,以及为什么父子关联exists子查询会对父查询构成筛选作用,解释起来需要很大的篇幅这里就不讲了。反正我们记住父子关联查询的最常用功能就是它可以求出两张表的交集或非交集(使用not关键字)和不使用group分组的情况下求出某张表的最大值或最小值。

现在回到题主的具体问题上,这个问题涉及到三张表,学生表student、选课表sc、课程表course。

提问要求列出选取了所有课程的学生名单。
下面是提问中给出的sql语句:

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 exists选出
...
select * from course
where not exists(
select * from sc
sno=student.sno
and cno=course.cno) .

热点内容
win2008的ftp设置 发布:2025-05-14 17:03:31 浏览:663
莱克发的工资卡密码是多少 发布:2025-05-14 16:57:10 浏览:177
方舟怎么用自己的存档进入别人的服务器 发布:2025-05-14 16:46:25 浏览:877
微博视频高清上传设置 发布:2025-05-14 16:38:41 浏览:548
数据库图书管理设计 发布:2025-05-14 16:33:52 浏览:378
php开发的网页 发布:2025-05-14 16:22:03 浏览:477
服务器内存跑满了怎么回事 发布:2025-05-14 16:21:16 浏览:224
微信qq音乐缓存 发布:2025-05-14 16:16:16 浏览:469
c语言回收内存 发布:2025-05-14 16:16:08 浏览:144
2021国产安卓顶级旗舰买哪个 发布:2025-05-14 16:15:36 浏览:300