SQL分页语句格式
2013-11-19 11:11
330 查看
使用between分页的,要用rownumber,因为要防止有些id不存在
pagesize=10
pageindex start=(pageindex-1)*10+1 end=pageindex*pagesize
select * from(select row_number() over(order by id) as num,* from tblname) as tbl
where num between start and end
使用top分页
pagesize=10
1页 select top 10 * from tblname where id not in(select top 0 id from tblname)
2页 select top 10 * from tblname where id not in(select top 10 id from tblname)
3页 select top 10 * from tblname where id not in(select top 20 id from tblname)
n页 select top pagesize * from tblname where id not in(select top (n-1)*pagesize id from tblname)
pagesize=10
pageindex | start | end |
---|---|---|
1页 | 1 | 10 |
2页 | 11 | 20 |
3页 | 21 | 30 |
select * from(select row_number() over(order by id) as num,* from tblname) as tbl
where num between start and end
使用top分页
pagesize=10
1页 select top 10 * from tblname where id not in(select top 0 id from tblname)
2页 select top 10 * from tblname where id not in(select top 10 id from tblname)
3页 select top 10 * from tblname where id not in(select top 20 id from tblname)
n页 select top pagesize * from tblname where id not in(select top (n-1)*pagesize id from tblname)
相关文章推荐
- SQL中的三值逻辑
- SQL Server 作业批量停止
- 结束SQL阻塞的进程
- 动态生成SQL Server视图作业
- SQL Server 语句操纵数据库
- linux快速部署mysql服务器
- sql 存储过程分页
- 在WINXP系统上安装SQL Server企业版的方法
- 通过批处理调用SQL的方法(osql)
- SQL Server 存储过程的分页
- ASP程序与SQL存储过程结合使用详解
- SQL SERVER编写存储过程小工具
- 防御SQL注入攻击时需要注意的一个问题
- SQL Server复制需要有实际的服务器名称才能连接到服务器
- SQL server 表操作介绍
- SQL Server 2000 注入防护大全(二)
- SQL Server 2000 注入防护大全(一)
- PJBlog存在SQL注入漏洞大家要快下补丁了