0419高级查询

高级查询

1连接查询 对列的拓展
select * from info,nation 这样得出的结果称为笛卡尔积 效率低

select * from info,nation where info.nation=nation.code

join on 链接
select * from info jion nation jion链接
select * from info jion nation on info.nation=nation.code

2 联合查询 对行的拓展
select code,name from info
union 链接的关键字
select codde,name from nation

3 子查询
1无关子查询 子查询查询的结果被父查询使用,子查询可以单独执行的称为无关子查询
select code from nation where name='汉族' 取nation表中查询汉族代号
select *from info where nation=(民族代号) 在inform表中查询民族代号为上一个查询结果的所有信息

2相关子查询
select * from car where oil<(该系列的平均油耗) 查询油耗小于该系列的平均油耗

select avg(oil) from car where brand='值' 查询该系列的平均油耗
select * from car a where oil<(select avg(oil) from car b where b. brand=a. brand)

原文地址:https://www.cnblogs.com/wcc731546227/p/5406920.html