--参考: 假设表中有唯一ID字段:--第一种方法 --第11条到第30条,共选出20条记录 select * from (select top 20 * from (select top 30 * from 表名 order by ID) t1 order by ID desc) t2 order by ID --第二种方法 --第11条到第30条,共选出20条记录 select top 20 * from 表名 where ID>(select max(ID) from (select top 10 ID from 表名 order by ID) t1) order by ID
1 select top 100 from 表名 order by id DESC--倒序下取前100即可2 t1,t2分别是他们前面的结果集的别名,这时sql的格式问题,名字随便起,叫什么都行,只要别重复。
select top 101 ID from A where ID not in ( select top 500 ID from A )
早晨刚上班还没睡醒我刚才的sql写错了 ,应该是: select top 100 * from 表名 where id not in(select top 500 id from 表名) order by id DESC
select top 99 * from test t where t.id not in (select top 501 id from test)
select * from (select top 20 * from (select top 30 * from 表名 order by ID desc) t1 order by ID desc) t2 order by ID
刚才不对,以下可以: select * from (select top 20 * from (select top 30 * from 表名 order by ID) t1 order by ID desc) t2 order by ID
假设表中有唯一ID字段:--第一种方法
--第11条到第30条,共选出20条记录
select *
from (select top 20 * from (select top 30 * from 表名 order by ID) t1 order by ID desc) t2
order by ID
--第二种方法
--第11条到第30条,共选出20条记录
select top 20 *
from 表名
where ID>(select max(ID) from (select top 10 ID from 表名 order by ID) t1)
order by ID
(
select top 500 ID from A
)
,应该是:
select top 100 *
from 表名
where id not in(select top 500 id from 表名)
order by id DESC
(select top 501 id from test)
from (select top 20 * from (select top 30 * from 表名 order by ID desc) t1 order by ID desc) t2
order by ID
select *
from (select top 20 * from (select top 30 * from 表名 order by ID) t1 order by ID desc) t2
order by ID