--第一种方法 --第11条到第20条,共选出10条记录 select * from (select top 10 * from (select top 20 * from 表名 order by ID) t1 order by ID desc) t2 order by ID --第二种方法 --第11条到第20条,共选出10条记录 select top 10 * from 表名 where ID>(select max(ID) from (select top 10 ID from 表名 order by ID) t1) order by ID
select id=IDENTITY(int, 1,1),* into temp from tableselect * from temp where id>= 30 and id <= 40
select top 10 * from (select top 40 * from table order by id) t order by id desc
select id=IDENTITY(int, 1,1),* into temp from tableselect * from temp where id>= 30 and id <= 40 ==================== 多一个ID字段
select TOP 40 id=IDENTITY(int, 1,1),* into #T from TableName select * from #T where id>= 30 and id <= 40 DROP TABLE #T
select TOP 40 id=IDENTITY(int, 1,1),* into #T from TableName select * from #T where id>=30 DROP TABLE #T
--第11条到第20条,共选出10条记录
select *
from (select top 10 * from (select top 20 * from 表名 order by ID) t1 order by ID desc) t2
order by ID
--第二种方法
--第11条到第20条,共选出10条记录
select top 10 *
from 表名
where ID>(select max(ID) from (select top 10 ID from 表名 order by ID) t1)
order by ID
from (select top 40 * from table order by id) t
order by id desc
====================
多一个ID字段
select * from #T where id>= 30 and id <= 40
DROP TABLE #T
select * from #T where id>=30
DROP TABLE #T