是要在一个表中的,表结构如下:
ID  A1  B1  A2  B2
1   a1  b1  a2  b2
2   a10 b10 a20 b20
转换成
ID  A1  B1
1   a1  b1
2   a10 b10
3   a2  b2
4   a20 b20
可以这样转换吗?

解决方案 »

  1.   

    select A1,B1 from tbname
    union all
    select A2,B2 from tbname
      

  2.   

    select a1,b1 from 表
    union all
    select a2 as a1,b2 as b2 from 表
      

  3.   

    --Code
    select row_number() over(order by A1) as id,t.* from
    (
    select A1,B1 from @T
    union all
    select A2,B2 from @T
    ) t
    --Drop--Result
    /*
    id                   A1   B1
    -------------------- ---- ----
    1                    a1   b1
    2                    a10  b10
    3                    a2   b2
    4                    a20  b20
    */
      

  4.   

    select row_number() over(order by A1) as id,t.* from
    (
    select A1,B1 from @T
    union all
    select A2,B2 from @T
    ) t
    强大
      

  5.   

    是要在一个表中的,表结构如下: 
    ID  A1  B1  A2  B2 
    1  a1  b1  a2  b2 
    2  a10 b10 a20 b20 
    转换成 
    ID  A1  B1 
    1  a1  b1 
    2  a10 b10 
    3  a2  b2 
    4  a20 b20 
    可以这样转换吗?select A1,B1
    from 表 
    union
    select A2,B2
    from 表