平时很少用的这几个操作,今天遇到了。于是又看了一下文档。
SOME和ANY一样,是比较宽松的,类似于OR。满足其中任何一个都可以。
ALL要求严格一些,类似于AND,必须全部满足才可以。
不能单独使用: Must be preceded by =, !=, >, <, <=, >=.
其实更应该关注的是紧跟着的备注信息,这个一开始比较难以理解。
SOME (ANY)
Evaluates to FALSE if the query returns no rows.
ALL
Evaluates to TRUE if the query returns no rows.
做个测试吧。
先看基本信息。
SQL> select max(salary) from employees;
MAX(SALARY)
-----------
24000
SQL> select min(salary) from employees;
MIN(SALARY)
-----------
2100
SQL> select count(1) from employees;
COUNT(1)
----------
107
SQL>
再试试结果。
SQL> SELECT count(1) FROM employees WHERE salary >= any (select 1 from dual where 1 < 1);
COUNT(1)
----------
0
SQL> SELECT count(1) FROM employees WHERE salary >= some (select 1 from dual where 1 < 1);
COUNT(1)
----------
0
SQL> SELECT count(1) FROM employees WHERE salary <= ALL (select 1 from dual where 1 < 1);
COUNT(1)
----------
107
SQL>