用一句SQL取出第 m 条到第 n 条记录的方法
1 --从Table 表中取出第 m 条到第 n 条的记录:(Not In 版本)
2
3 SELECT TOP n-m+1 *
4 FROM Table
5 WHERE (id NOT IN (SELECT TOP m-1 id FROM Table ))
6
7
8 --从TABLE表中取出第m到n条记录 (Exists版本)
9
10 SELECT TOP n-m+1 * FROM TABLE AS a WHERE Not Exists
11 (Select * From (Select Top m-1 * From TABLE order by id) b Where b.id=a.id )
12 Order by id
13
14
15 --m为上标,n为下标,例如取出第8到12条记录,m=8,n=12,Table为表名
16
17 Select Top n-m+1 * From Table
18 Where Id>(Select Max(Id) From
19 (Select Top m-1 Id From Table Order By Id Asc) Temp)
20 Order By Id Asc