有这个一个数据表,如果想把行的部分内容转换成列来显示该如何实现? 感谢~a1 b1 c1 E F G I J K L M N ……
a2 b2 c2 e f g i j k l m n ……
……
转换成a1 b1 c1 E F G   ......
a1 b1 c1 I J K
a1 b1 c1 L M N
a2 b2 c2 E F G
a2 b2 c2 I J K
a2 b2 c2 L M N
......

解决方案 »

  1.   

    需要动态的话 不需要的话直接UNION ALL搞定。交给楼下了。
      

  2.   

    用max case when 及group by结合,网上一搜一堆
      

  3.   

    你这个列数如果是固定的,还是可以考虑 用 UNION ALL , 看到你的列是后 3+n 列,要变成 3+ 3 UNION ALL 3+3 样式col1 , col2 , col3 , col4 , col5 , col6 , col7............col30select col1 , col2 , col3 , col4 , col5 , col6 
    union all
    select col1 , col2 , col3 , col7 , col8 , col9 
      

  4.   

    select a1 b1 c1 E F G 
    union all
    select a1 b1 c1 I J K
    union all
    select a1 b1 c1 L M N
    union all
    select a2 b2 c2 E F G
    union all
    select a2 b2 c2 I J K .....