some,any,all的简单学习
2013-09-29 11:35
141 查看
/*
一:用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
一:用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
相关文章推荐
- Oracle的SOME,ANY和ALL操作
- MySQL中子查询IN,EXISTS,ANY,ALL,SOME,UNION介绍
- 关于运算符IN、ANY、ALL、NOT、SOME
- any、some、all for sql
- oracle中exists、in、any、all、some的用法
- sql中ANY、SOME、ALL关键字
- (转)用 ANY、SOME 或 ALL 修改的比较运算符
- 在oracle的子查询中使用some,any和all
- MySQL嵌套查询“LIMIT & IN/ALL/ANY/SOME”错误解决方法
- MySQL嵌套查询“LIMIT & IN/ALL/ANY/SOME”错误解决方法
- all 、any 、some的使用
- This version of MySQL doesn't yet support 'LIMIT & IN/ALL/ANY/SOME subquery' 错误解决
- Mysql:This version of MySQL doesn’t yet support ‘LIMIT & IN/ALL/ANY/SOME 错误解决
- mysql笔记-[Err] 1235 - This version of MariaDB doesn't yet support 'LIMIT & IN/ALL/ANY/SOME subquery'
- mysql子查询用limit报错( “This version of MySQL doesn’t yet support ‘LIMIT & IN/ALL/ANY/SOME subquery’ ”)
- sql中all,any,some
- 1235 - This version of MySQL doesn't yet support 'LIMIT & IN/ALL/ANY/SOME subquery'
- Oracle中 oracle中any,some,all用法
- 关于SOME、ANY和ALL的区别
- Oracle的SOME,ANY和ALL操作