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 * 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