dreamhappy2012

2018-11-27   阅读量: 688

Mysql

子查询

扫码加入数据分析学习群

子查询:写在()中,把内层查询结果当做外层查询参照的数据表来用

例: 用in操作符与子查询语句来查询所有f_id对应的f_price在10元到20元之间的水果记录

select * from fruits where f_id in

(select f_id from fruits where f_price between 10 and 20);

例: 用any操作符与子查询语句来查询所有f_id对应的f_price在10元到20元之间的水果记录

select * from fruits where f_id = any

(select f_id from fruits where f_price between 10 and 20);

例: 用all操作符与子查询语句来查询所有f_price大于20元的水果记录

select * from fruits where f_price > all

(select f_price from fruits where f_price < 20);

例: 用exists操作符与子查询语句来查询是否存在f_price大于30元的水果记录

select * from fruits where exists

(select * from fruits where f_price > 30);

添加CDA认证专家【维克多阿涛】,微信号:【cdashijiazhuang】,提供数据分析指导及CDA考试秘籍。已助千人通过CDA数字化人才认证。欢迎交流,共同成长!
0.0000 0 3 关注作者 收藏

评论(0)


暂无数据

推荐课程