从第N条开始取M条
select top M * from tables where 主键 not in (select top N 主键 from tables)
从第N条取到第M条
select top M-N * from tables where 主键 not in (select top N 主键 from tables)
要求表要有主键,M>N
另还有一种:将结果集放入一个临时表中(#tmp),在建临时表时给其加一个自增字段.
然后再通过这个自增字段来选取所需记录.
select identity(int,0,1) as tmpid,* into #tmp from table where ......
identity(int,0,1) as tmpid:做一个自增数,类型为Int,从0开始,增量1.别名为tmpid.
select * into #tmptable from table:将此次select的结果放入一个临时表#tmptable中.
从第N条取到第M条
select * from #tmp where tmpid>=N and tmpid<=M;
从第N条开始取M条
select * from #tmp where tmpid>=M and tmpid<=N+M;