比如我有一个表,查出的记录:
c1 c2 c3 c4 c5 c6 c7 c8 c9 c10 列名
a b c d e f g h j k 列值
我现在想把行转化成列,如何写:

c1
a
c2
b
c3
c
c4
d
.
.
.
.
.
c10
k

解决方案 »

  1.   

    上面写错了,这样:
    c1 a
    c2 b
    c3 c
    c4 d.
    .
    .
    .
    c10 k
      

  2.   

    比如我有一个表,查出的记录:
    id  c1  c2  c3  c4  c5  c6  c7  c8  c9  c10     列名
    2  a    b    c    d     e    f     g     h   j     k        列值
    我现在想把行转化成列,如何写:

    2   c1     a
    2     c2     b
    2     c3     c
    2     c4     d.
    .
    .
    .
    2    c10    k
      

  3.   

    select 'c1' as "新列1",c1 as "新列2" from table
    union all
    select 'c2' as "新列1",c2 as "新列2" from table
    union all
    select 'c3' as "新列1",c3 as "新列2" from table
    ...
    union all
    select 'c10' as "新列1",c10 as "新列2" from table
    古怪的需求
      

  4.   

    变的真快,
    select 'c10' as "新列1",c10 as "新列2" from table
    =>
    select id,'c10' as "新列1",c10 as "新列2" from table
      

  5.   

    select 'c2' as "新列1",c2 as "新列2" from table where c2 is not null
    把where c2 is not null放在from table后面