zoukankan      html  css  js  c++  java
  • SqlServer分页查询语句

    语句如下:

    declare @page int
    declare @size int
    
    set @page=2
    set @size=20 
    
    --第一种,优点,RowId可以作为行数,只扫描一次表数据,逻辑读取两次
    SET STATISTICS PROFILE ON 
    SET STATISTICS IO ON 
    SET STATISTICS TIME ON 
     /*--你的SQL脚本开始*/
    select * from (select top (@page*@size) row_number() over(order by Id) RowId,* from T1 order by RowId) T where RowId between (@page*@size-@size+1) and (@page*@size)
    --between 结果会包含边界值,所以需要+1
    /*--你的SQL脚本结束*/ SET STATISTICS PROFILE OFF SET STATISTICS IO OFF SET STATISTICS TIME OFF --第二种 扫描两次表数据,逻辑读取四次 SET STATISTICS PROFILE ON SET STATISTICS IO ON SET STATISTICS TIME ON /*--你的SQL脚本开始*/ select top (@size) * from T1 where Id not in(select top (@page*@size-@size) ID from T1 order by Id)order by Id /*--你的SQL脚本结束*/ SET STATISTICS PROFILE OFF SET STATISTICS IO OFF SET STATISTICS TIME OFF

    结果如下:

    推荐使用第一种方式 分页

  • 相关阅读:
    js 数据类型的转换
    js数组学习方法汇总
    跳转页面的方法总结
    今天用js做拉一个时钟
    今天用js做拉一个时钟
    js中字符的比较
    1005 继续(3n+1)猜想 (25分)
    1002 写出这个数
    日期差值
    1040 有几个PAT (25分)
  • 原文地址:https://www.cnblogs.com/Med1tator/p/9244416.html
Copyright © 2011-2022 走看看