子查询中特定关键字使用
1. in 范围
格式: 主查询 where 条件 in (列子查询)
查询18-20岁的学生。
select *
from students
where age in (select age from students where age between 18 and 20);
2. any | some 任意一个
格式: 主查询 where 列 = any (列子查询)
在条件查询的结果中匹配任意一个即可,等价于 in
格式: 主查询 where 列 < 、>any (列子查询)
在条件查询的结果中小于或者大于任意一个即可,等价于 in
select *
from students
where age=any(select age from students where age between 18 and 20);
3. all
格式: 主查询 where 列 = all(列子查询) : 等于里面所有
格式: 主查询 where 列 <all(列子查询) :小于最小值
格式: 主查询 where 列 <>all(列子查询) : 不等一其中所有
select * from students where age in (select age from students where age between 18 and
20)