27,580
社区成员
发帖
与我相关
我的任务
分享
select top 40 * from table ORDER BY ID
except
select top 30 * from table ORDER BY ID
select tt.*
from
(
select top 40 id from table
except
select top 30 id from table
)t
inner join table tt on tt.id = t.id
没主键的情况
--首先,生成带记录号的临时表
select id=identity(int,1,1),* into #temp
--然后,就可以用下面的语句检索出第M到N条记录:
select * from #temp where id between m and n
2.有主键的情况
检索出第m页,每页共n条记录的语句
select top n from 你的表 where 主键 not in(select (m-1) * n 主键 from 你的表)
m,n均为常量,不能为变量