当前位置:Gxlcms > 数据库问题 > 数据库部分---高级查询;

数据库部分---高级查询;

时间:2021-07-01 10:21:17 帮助过:37人阅读

把子查询的语句放到父查询的括号内

结合起来:select * from info where nation=(select code from nation where name=‘汉族‘)        相当于nation=(code)

技术分享

技术分享

 2.查询系列名为宝马5的所有汽车信息

技术分享

技术分享

技术分享

技术分享

 

(2)相关子查询

子查询在执行的时候和父查询有关系,子查询不可以单独执行

1.查询汽车表中油耗小于该系列平均油耗的所有汽车信息

父查询:select * from car where oil<(该系列平均油耗)

子查询:select avg(oil) from car where brand=该系列

select * from car where oil<(select avg(oil) from car where brand=该系列)

由于父查询和子查询都是查询的一张表,所以我们给父查询查询的表名,子查询查询的表名进行命名,

select * from car as aa where oil<(select avg(oil) from car as bb where brand=该系列)

然后再确定‘该系列’,

select * from car as aa where oil<(select avg(oil) from car as bb where bb.brand=aa.brand)

技术分享

 

技术分享

 

数据库部分---高级查询;

标签:image   结合   com   str   nat   and   数据   表名   avg   

人气教程排行