现在有1到n个整形数,中间可能有不连续的行
比如说......98,100,102,103,105,700,702,703,704,706......
我现在要将最后的12条记录取出,取出后有要按升序排列.
即是:  ....700,702,703,704,706,n请问如何实现呢?谢谢!!

解决方案 »

  1.   

    select top 12 [number] from tbXX order by [number] desc
      

  2.   

    declare @t table(num int)
    insert into @t select 98 
    union all select 100
    union all select 102
    union all select 103
    union all select 105
    union all select 700
    union all select 702
    union all select 703
    union all select 704
    union all select 706
    union all select 708
    union all select 710
    union all select 712
    union all select 714select [id]=identity(int,1,1),* into # from @t
    select * from (select top 12 * from # order by id desc)a order by a.id
    drop table #select * from (select top 12 * from @t order by num desc)a order by a.num
      

  3.   

    看漏眼了……
    select * from tbXX where [number] in (select top 12 [number] from tbXX order by [number] desc)
      

  4.   

    select top 12 * from (select count(ipAddr) as zongshu, DateName(yyyy,ipTime)+'-'+ DateName(mm, iptime) as whenTime from tblIpAddress group by DateName(yyyy,ipTime)+'-'+ DateName(mm, iptime) order by DateName(yyyy,ipTime)+'-'+ DateName(mm, iptime)) a order by a.whenTime descbulajsdf不知道为什么不行呢?
    报错说“除非同时指定了 TOP,否则 ORDER BY 子句在视图、内嵌函数、派生表和子查询中无效。”
      

  5.   

    create table tbl (num int)
    insert into tbl select 1
          union all select 2
          union all select 3
          union all select 4
          union all select 6
          union all select 7
          union all select 9
          union all select 10
          union all select 15
          union all select 700
          union all select 702
          union all select 703
          union all select 708
          union all select 710
          union all select 715
          union all select 720select num from (select top 12 num from tbl order by num desc) t order by num