datagrid连接access的快速分页法(3)——sql语句的选用(降序) 三、降序 (1)@pageindex <= @firstindex select top @pagesize @queryfields from @tablename where @condition order by @primarykey desc
(2)@firstindex < @pageindex <= @middleindex
select top @pagesize @queryfields from @tablename where @primarykey < ( select min(@primarykey) from ( select top @pagesize*@pageindex @primarykey from @tablename where @condition order by @primarykey desc ) tablea ) where @condition order by @primarykey desc
(3)@middleindex < @pageindex < @lastindex
select * from ( select top @pagesize @queryfields from @tablename where @primarykey > ( select max(@primarykey) from ( select top (@[email protected]*(@pageindex+1)) @primarykey from @tablename where @condition -- order by @primarykey asc ) tablea ) where @condition -- order by @primarykey asc ) tableb order by @primarykey desc
(4)@pageindex >= @lastindex
select * from ( select top (@[email protected]*@lastindex) @queryfields from @tablename where @condition order by @primarykey asc ) tablea order by @primarykey desc