查询N-M条记录。 select IDENTITY(int,1,1) as iid,* into #temptable from yourtable select top M-N * from #temptable where iid>=NOR:select top M-N * from yourTable where id not in(select top N-1 id from table) ID为表具有唯一值的任何字段
方法一:取出前n条和前m条然后取出其差(n-m) select top(n-m) * from table where 关键字段 not in(select top m 关键字段 from table)方法二:先取出前n条的,再倒过来取出n-m就可以 select top(n-m+1) * from (select top n * from table order by 关键字段 desc) order by 关键字段
更正: select * from (select identity(1,1) as id,top b * from table) a where a.id not in(select b.id from (select identity(1,1) as id, top a * from table) as b)或者 select identity(1,1) as id, * into #temp from table select * from #temp where id>=a and id<=b
select top b-a * from yourTable where id not in(select top a-1 id from table) ID为表具有唯一值的任何字段或任何字段的组合 同时注意top 后面不支持参数,如果含参数执行要用exec exec('select top '+@b-@a 的变量 +' * from yourTable where id not in(select top' + @a-1 的变量+' id from table)' ) 如果没有唯一值,按照蚂蚁的就可以了
select IDENTITY(int,1,1) as iid,* into #temptable from yourtable
select top M-N * from #temptable where iid>=NOR:select top M-N * from yourTable where id not in(select top N-1 id from table)
ID为表具有唯一值的任何字段
select top(n-m) *
from table
where 关键字段 not in(select top m 关键字段 from table)方法二:先取出前n条的,再倒过来取出n-m就可以
select top(n-m+1) *
from (select top n * from table order by 关键字段 desc)
order by 关键字段
select * from (select identity(1,1) as id,top b * from table) a where a.id not in(select b.id from (select identity(1,1) as id, top a * from table) as b)或者
select identity(1,1) as id, * into #temp from table
select * from #temp where id>=a and id<=b
ID为表具有唯一值的任何字段或任何字段的组合
同时注意top 后面不支持参数,如果含参数执行要用exec
exec('select top '+@b-@a 的变量 +' * from yourTable where id not in(select top' + @a-1 的变量+' id from table)'
)
如果没有唯一值,按照蚂蚁的就可以了