Oracle-範圍條件-in exists some any all 辨析
目錄
文章目錄
-
- 1、in和exists
- 2、some/any和all
-
- 2.1、基本含義
- 2.2、some/any 和all辨析
- 2.3、示例
- ***後記*** :
内容
1、in和exists
- in:
where 字段 in (值1, 值2, ..., 值n) 等同于:字段 = 值1 or 字段 = 值2 or ... or 字段 = 值n
- 解析:判斷字段值是否在in後面集合中
- exists:
where exists (select )
- 示例:查詢10号部門和20号部門所有員工的資訊。
- in
select * from emp where deptno in(10, 20);
- exists
select * from emp where exists(10, 20);
- in
2、some/any和all
2.1、基本含義
- some :某一個
- any:任意一個
- all:所有
- 格式:
where 字段 =/<> some/any/all(值1, 值2, ..., 值n)
2.2、some/any 和all辨析
- some和any用法相同,結果相同,一般=後面接some,非=後面接any
- 規律:
some | any | all | |
---|---|---|---|
> | >min | >min | >max |
< | <max | <max | <min |
2.3、示例
- 查詢工作和20号部門某個員工工作相同的員工資訊
- in
select * from emp where job in ( select job from emp where deptno = 20 );
- some
select * from emp where job = some( select job from emp where deptno = 20 );
- in
- 查詢工資高于20号部門某個員工工資的員工的資訊
select * from emp where sal > any( select sal from emp where deptno = 20 );
- 查詢工資高于20号部門所有員工工資的員工的資訊
select * from emp where sal > all( select sal from emp where deptno = 20 );
後記 :
所有資料庫測試如果沒有明确指定,都是基于scott使用者下預設4個表。
本項目為參考某馬視訊開發,相關視訊及配套資料可自行度娘或者聯系本人。上面為自己編寫的開發文檔,持續更新。歡迎交流,本人QQ:806797785。
前端項目源代碼位址:https://gitee.com/gaogzhen/vue-leyou
後端JAVA源代碼位址:https://gitee.com/gaogzhen/JAVA