用一句SQL取出第 m 条到第 n 条记录的方法
从Table 表中取出第 m 条到第 n 条的记录:(Not In 版本)
SELECT TOP n-m+1 *
FROM Table
WHERE (id NOT IN (SELECT TOP m-1 id FROM Table ))
--从TABLE表中取出第m到n条记录 (Exists版本)
SELECT TOP n-m+1 * FROM TABLE AS a WHERE Not Exists
(Select * From (Select Top m-1 * From TABLE order by id) b Where b.id=a.id )
Order by id
--m为上标,n为下标,例如取出第8到12条记录,m=8,n=12,Table为表名
Select Top n-m+1 * From Table
Where Id>(Select Max(Id) From
(Select Top m-1 Id From Table Order By Id Asc) Temp)
Order By Id Asc
SELECT TOP n-m+1 *
FROM Table
WHERE (id NOT IN (SELECT TOP m-1 id FROM Table ))
--从TABLE表中取出第m到n条记录 (Exists版本)
SELECT TOP n-m+1 * FROM TABLE AS a WHERE Not Exists
(Select * From (Select Top m-1 * From TABLE order by id) b Where b.id=a.id )
Order by id
--m为上标,n为下标,例如取出第8到12条记录,m=8,n=12,Table为表名
Select Top n-m+1 * From Table
Where Id>(Select Max(Id) From
(Select Top m-1 Id From Table Order By Id Asc) Temp)
Order By Id Asc
申明
非源创博文中的内容均收集自网上,若有侵权之处,请及时联络,我会在第一时间内删除.再次说声抱歉!!!
博文欢迎转载,但请给出原文连接。