select t.* from (select top 20 * from 表 order by id desc) t order by t.id

解决方案 »

  1.   

    取降序排列的前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
      

  2.   

    select t.* from (select top 20 * from 表 order by id desc) t order by t.id
      

  3.   

    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
      

  4.   

    select * from (select top 20 * from a order by id ) T order by id DESC