閱讀246 返回首頁    go 阿裏雲 go 技術社區[雲棲]


Oracle中的Exists、In、ANY、ALL

Exists:子查詢至少返回一行時條件為true。

Not Exists:子查詢不返回任何一行時條件為true。

In:與子查詢返回結果集中某個值相等。

Not In:與子查詢返回結果集中任何一個值不相等。

>ANY:比子查詢返回結果中的某個值大。

=ANY:與子查詢返回結果中的某個值相等。

<ANY:比子查詢返回結果中的某個值小。

>ALL:比子查詢返回結果中的所有值都大。

<ALL :比子查詢返回結果中的所有值都小。

1、查詢與10號部門某個員工工資相等的員工信息。

select empno ,ename,sal from emp 
where sal in(select sal from emp where deptno=10)

下麵這句話與上的語句效果一樣

select empno ,ename,sal from emp 
where sal=any(select sal from emp where deptno=10)

效果如下圖:


小注:

        =any()括號中即使出現重複的值,也不會報錯,比如:

select empno ,ename,sal from emp 
where sal=any(2450.00,5000.00,5000.00)
2、查詢比10號部門某個員工工資高的員工信息。

select empno ,ename,sal from emp 
where sal >any(select sal from emp where deptno=10)

在emp表中工資的最小值為1300,下麵這句話與上麵語句的效果一樣

select empno ,ename,sal from emp 
where sal >1300

效果如下圖:


3、查詢比10號部門所有員工工資高的員工信息。

select empno ,ename,sal from emp 
where sal >all(select sal from emp where deptno=10)

效果如下圖(沒有查詢到數據):



最後更新:2017-04-03 12:54:58

  上一篇:go Oracle 連接查詢
  下一篇:go 在Ubuntu為Android硬件抽象層(HAL)模塊編寫JNI方法提供Java訪問硬件服務接口