select a,b,c,d from tb
union all
select a1,b1,c1,d1 from tb
union all
select a2,b2,c2,d2 from tb

解决方案 »

  1.   

    if object_id('tempdb..#')is not null drop table #
    go
    create table #(A int,  B int,  C int,  D int ,  A1 int,  B1 int,  C1 int ,  D1 int,  A2 int,  B2 int,  C2 int,  D2 int) 
    insert # select 1 , 2,  3,  4,  5,  6,  7,  8,  9,  10,  11,  12
    select a,b,c,d from #
    union all
    select a1,b1,c1,d1 from #
    union all
    select a2,b2,c2,d2 from # 
    /*a           b           c           d           
    ----------- ----------- ----------- ----------- 
    1           2           3           4
    5           6           7           8
    9           10          11          12*/
      

  2.   

    create table tb(A int,  B int,  C int,  D int ,  A1 int,  B1 int,  C1 int ,  D1 int,  A2 int,  B2 int,  C2 int,  D2 int) 
    insert tb select 1 , 2,  3,  4,  5,  6,  7,  8,  9,  10,  11,  12
    goselect a,b,c,d from tb
    union all
    select a1,b1,c1,d1 from tb
    union all
    select a2,b2,c2,d2 from tbdrop table tb/*
    a           b           c           d           
    ----------- ----------- ----------- ----------- 
    1           2           3           4
    5           6           7           8
    9           10          11          12(所影响的行数为 3 行)
    */