some,any,all的簡單學習

來源:互聯網
上載者:User

/*

一:用some,any 和all對子查詢中返回的多行結果進行處理。

1.some在此滿足其中一個的意義,是用or串起來的比較從句。

2.any也表示滿足其中一個的意義,也是用or串起來的比較從句。

3.all則滿足其中所有的查詢結果的含義,使用and串起來的比較從句。


例子1:

select * from tableA where fld > all(select fld from tableA);

相當於

select * from tableA where fld > (select max(fld) from tableA);



例子2:

select * from tableA where fld < any(select fld from tableA);

相當於

select * from tableA where fld < (select min(fld) from tableA);




例子3:

select * from tableA where fld = any(select fld from tableA);

相當於

select * from tableA where fld in(select fld from tableA);


*/


/*4.

找出員工中,只要比部門號為10的員工中的任何一個員工的工資高的員工的姓名和工資。

也就是說只要比部門號為10的員工中那個工資最少的員工的工資高的就滿足條件。

*/

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

--其實相當於下面的代碼

select ename,sal from emp where sal > (select min(sal) from emp where deptno = 10);

--當然你也可以用some,但是更推薦用any。下面一個方法才是some的常用方法。



/*5.找到和30部門員工的任何一個人的工資相同的那些員工*/

select ename,sal from emp where sal = some(select sal from emp where deptno = 30) and deptno not in(select deptno from emp where deptno = 30);



/*6.找到比部門號20的員工的所有員工的工資都要高的員工*/

select ename,sal from emp where sal > all(select sal from emp where deptno = 20);


本文出自 “我的JAVA世界” 部落格,請務必保留此出處http://hanchaohan.blog.51cto.com/2996417/1303335

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.