首页 > 代码库 > 常见的三种SQL分页方式
常见的三种SQL分页方式
- --top not in方式
- select top 条数 * from tablename
- where Id not in (select top 条数*页数 Id from tablename)
- --ROW_NUMBER() OVER()方式
- select * from (
- select *, ROW_NUMBER() OVER(Order by Id ) AS RowNumber from tablename
- ) as b
- where RowNumber BETWEEN 当前页数-1*条数 and 页数*条数
- --offset fetch next方式
- --SQL2012以上的版本才支持
- select * from tablename
- order by Id offset 页数 row fetch next 条数 row only
分析:在数据量较大时
top not in方式:查询靠前的数据速度较快
ROW_NUMBER() OVER()方式:查询靠后的数据速度比上一种较快
offset fetch next方式:速度稳定,优于前2种,但sql版本限制2012及以上才可使用
常见的三种SQL分页方式
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。