取降序排列的前20条记录,然后按ID升序排列: select t.* from (select top 20 * from 表 order by id desc) t order by t.id 取升序排列的前20条记录,然后按ID降序排列: select t.* from (select top 20 * from 表 order by id) t order by t.id desc
select t.* from (select top 20 * from 表 order by id desc) t order by t.id
create table #A ([id] int,A nvarchar(100), B datetime) insert into #A select 1,'aaa', getdate() insert into #A select 2,'bbb', getdate() insert into #A select 3,'ccc', getdate() insert into #A select 4,'ccc', getdate()-11 insert into #A select 5,'ccc', getdate()-12 insert into #A select 6,'ccc', getdate()-13 insert into #A select 7,'ccc', getdate()-20select * from (select top 3 * from #A order by [id] desc) a
select * from (select top 20 * from a order by id ) T order by id DESC
select t.* from (select top 20 * from 表 order by id desc) t order by t.id
取升序排列的前20条记录,然后按ID降序排列:
select t.* from (select top 20 * from 表 order by id) t order by t.id desc
insert into #A select 1,'aaa', getdate()
insert into #A select 2,'bbb', getdate()
insert into #A select 3,'ccc', getdate()
insert into #A select 4,'ccc', getdate()-11
insert into #A select 5,'ccc', getdate()-12
insert into #A select 6,'ccc', getdate()-13
insert into #A select 7,'ccc', getdate()-20select * from
(select top 3 * from #A order by [id] desc) a