首页 > 其他 > 详细

0419高级查询

时间:2016-04-19 10:05:01      阅读:141      评论:0      收藏:0      [点我收藏+]

高级查询

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)

0419高级查询

原文:http://www.cnblogs.com/wcc731546227/p/5406920.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!