some、any、all 三个谓词,都是用于一组数据,而不针对单个数据。
下面举例说明。
select ename,sal
From emp
Where sal > any(select sal from emp where deptno = 10);
从emp表中选出大于部门10中最小工资的的人的姓名和工资。
小结:any是大于最小,小于最大。(当然此处使用some也可以,但any语义更为直接)
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);
从emp表中选出不是30号部门,但工资和30号部门任何一个人的工资相等的人的姓名和工资。
小结:等于任意一个。
select ename,sal
From emp
Where sal > all(select sal from emp where deptno = 20);
从emp表中选出工资大于20号部门最大工资的人的姓名及工资。
小结:大于最大,小于最小。
下面举例说明。
select ename,sal
From emp
Where sal > any(select sal from emp where deptno = 10);
从emp表中选出大于部门10中最小工资的的人的姓名和工资。
小结:any是大于最小,小于最大。(当然此处使用some也可以,但any语义更为直接)
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);
从emp表中选出不是30号部门,但工资和30号部门任何一个人的工资相等的人的姓名和工资。
小结:等于任意一个。
select ename,sal
From emp
Where sal > all(select sal from emp where deptno = 20);
从emp表中选出工资大于20号部门最大工资的人的姓名及工资。
小结:大于最大,小于最小。