写在()中的为子查询. 把内层查询结果当做外层参照的数据来查询
– 运用fruits 数据
select * from fruits;
-- in
#查询价格在10-20之间的信息
select * from fruits where f_id in
(select f_id from fruits where f_price between 10 and 20);
-- 实现方式二
select * from fruits
group by f_id having f_price between 10 and 20 ;
-- any 可配合比较符号
select * from fruits where f_id = any
(select f_price from fruits where f_price between 10 and 20);
-- all 可配合比较符号
select * from fruits where f_price > all
(select f_price from fruits where f_price <20);
-- 方式二
select * from fruits where f_price > 20;
-- exists 存在
select * from fruits where exists
(select * from fruits where f_price >30);
上述的子查询的共同点是查询结果是具体的数值