sqlserver 2012 windowing functions Fast Page

Started to build the table insert value

create table test(
  keyid int identity,
  sort varchar(10),
  qty int
) 

Insert data, specifically data is deleted a id to 7, so that ID is not continuous!
Here Insert Picture Description
Next, paging sql

select COUNT(1) OVER () as [总数],* from test 
order by keyid offset 0 rows fetch next 7 rows only

Here Insert Picture Description
Note 0 Here is more offset ID to retrieve the actual value is an index, starting from 0 id nothing to do with the true value!
fetch next 7 rows only go 7 represents data transfer from the rear offset

The final method is to write about it

select COUNT(1) OVER () as [总数],* from test 
order by keyid offset   每页数量 * (页码-1)    rows fetch next  每页数量  rows only
//这样就可以了

Welcome pointing!

Guess you like

Origin blog.csdn.net/weixin_42780928/article/details/91954951