嵌套查詢中關於any/some/all的使用

some相當於or
all相當於and
 
當[select sal from scott.emp where job='manager'; 結果爲 sal:2975 2850 2450] 時
select emp.empno,emp.ename,emp.sal from scott.emp where sal=some(select sal from scott.emp where job='manager');
等價於
select emp.empno,emp.ename,emp.sal from scott.emp where sal=2975 or sal=2850 or sal=2450;
或者
select emp.empno,emp.ename,emp.sal from scott.emp where sal in (2975,2850,2450); 
注:any與some是等價的

當[select sal from scott.emp where job='manager'; 結果爲 sal:2975 2850 2450] 時
select emp.empno,emp.ename,emp.sal from scott.emp where sal>all(select sal from scott.emp where job='manager');
等價於
select emp.empno,emp.ename,emp.sal from scott.emp where sal>2975 and sal>2850 and sal>2450;
 
<>all ()與not in是等價的,但是=all()不等價與in,因爲=不能對應多個值。
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章