/*
一:用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);
本文转自韩立伟 51CTO博客,原文链接:http://blog.51cto.com/hanchaohan/1303335,如需转载请自行联系原作者