要领1:运用select top合营not in(或许not exists),查询第n页的时刻,过滤掉n-1页的数据即可,示例假定每页查询数目为5,查询第3页的数据;
Select Top 5 UserCode,UserName from userInfo where UserCode not in (select top ((3-1)*5) UserCode from UserInfo order by UserCode asc) order by UserCode asc
前15行的数据
第三页的数据
注重查询的时刻order by 必需运用雷同的列及分列;
要领2:运用Row_Number()内置函数,先给查询的表加上一列ID,然后查询第几页就很简朴了 between ..and...
select UserCode,UserName,PassWord From
(Select UserCode,UserName,PassWord,Rn=Row_Number() OVER(order by UserCode desc) From UserInfo) AS T
Where t.Rn between (3-1)*5 and 3*5
固然现实运用中每页纪录数目,查询第几页都可以运用参数来替代。
以上就是怎样操纵MSSQL查询数据分页 的细致内容,更多请关注ki4网别的相干文章!