首页 > 数据库技术 > 详细

步步为营-46-分页显示的SQL语句

时间:2017-05-06 16:26:54      阅读:363      评论:0      收藏:0      [点我收藏+]

说明:分页显示在实际业务中经常需要用到,其SQL语句分两种

技术分享
--方法一:跳过多少行,选中多少行
--每页n条,选择第m页--n=2 m=3
--select top(n) * fromwhere 主键 not in (select top(m-1)*n 主键 from 表);
select  * from UserInfo
select top(2) * from UserInfo where Empid not in (select top((3-1)*2) EmpId from UserInfo);
--方法二,通过rowNumber函数,但是只能当作临时表
select * from(select * ,ROW_NUMBER() over (order by EmpId) as num from UserInfo) as T
where T.num between (3-1)*2+1 and 3*2;
--over开窗函数的的另一个用法
select top(2) * ,AVG(StuAge) over() as 平均年龄 from UserInfo;
View Code

技术分享

 

步步为营-46-分页显示的SQL语句

原文:http://www.cnblogs.com/YK2012/p/6817105.html

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