table1字段 a  b   按b排序后生成table2    a1  b1
     1  9                          1  9 
     2  3                          3  7
     3  7                          2  3 现要两个表的合集  a  b  a1  b1
                   1  9   1   9
                   2  3   3   7
                   3  7   2   3 
                   
求sql  谢谢!

解决方案 »

  1.   

    select identity(int,1,1) as id , * into #a from table1select identity(int,1,1) as id,* into #b from table1
    order by b descselect #a.a,#a.b,#b.a as a1,#b.b as b1 from #a,#b
    where #a.id=#b.id
      

  2.   

    select id=identity(int,1,1),* into table2 from table1
    select id=identity(int,1,1),* into table3 from table1 order by b1 descselect table2.a,table2.b,table3.a1,table3.b2
    from table2,table3
    where table2.id = table3.id