码迷,mamicode.com
首页 > 其他好文 > 详细

高级查询

时间:2015-07-20 01:05:35      阅读:156      评论:0      收藏:0      [点我收藏+]

标签:

高级查询: 连接查询:

select*from 表名 join 表名 on 表名.列名=表名.列名  内连接两个表

select 1表名.1列名,2表名.2列名,3表名.3列名 from 1表名 join 3表名 on 3表名.sno列名=1表名.sno

join 2表名 on 2表名.cno=三表名.cno     连接三个列表

select*from 表名 right join 表名 on 表名.列名=表名.列名   右连接,右边必须显示全,如果左边没有对应值则空

select*from 表名 left join 表名 on 表名.列名=表名.列名    左连接,左边必须显示全,如果右边没有对应值则空

select*from 表名 full join 表名 on 表名.列名=表名.列名    全连接,左右两边的表都显示完全

 

联合查询:

select 要查的列,列名 from 表名

union                              对于查出的两个或多个结构相同的表联合显示

select 1表名+列,列  from 第二表名

子查询:

无关子查询:

先查select year(要查的一列名) from 表名 where 编号列称=‘p005‘

在查一次 select*from 表名 where year(要查的一列名)

全写select*from 表名 where year(要查的一列名)= select year(要查的一列名) from 表名 where 编号列称=‘p005‘

相关子查询:

select*from teacher t1 where 列称=‘列名‘ and not exists( select*from teacher t1 where 列称=‘列名‘ and t1.不同职称=t2.不同职称

--查询除了每门课最高分之外的其他学生信息 select * from Score s1 where Degree not in( select MAX(Degree) from Score s2 group by Cno having s1.Cno=s2.Cno ) --分页 select * from Car

select top 5 * from Car --前5条数据,第一页 select top 5 * from Car where Code not in( --第二页数据 select top 5 Code from Car ) select top 5 * from Car where Code not in( --第三页数据 select top 10 Code from Car ) select CEILING(COUNT(*)/5) from Car --求总页数

 

高级查询

标签:

原文地址:http://www.cnblogs.com/hansonglin/p/4660151.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!