表  A   B  C 3个字段
A     B         C
1     2         3需转成A    1
B    2
C    3

解决方案 »

  1.   


    select 'A' ,A from table where A='A'
    union all
    select 'B' ,B from table where B='B'
    union all
    select 'C' ,C from table where C='C'
      

  2.   

    有什么实际的需求吗?如果有的话就把实际的应用贴出来,单纯转这么一个ABC的话没有什么意义吧
      

  3.   

    select 访视日期,出生天数,体温,心率,体重,身长,皮肤,心,肺,脐部,臀红,黄疸,喂养方式,睡眠,大便,小便,疾病情况,出生缺陷,特殊情况记录,处理指导,访视人员,隶属机构 from  table1         然后把所有字段转成1列 结果为
           A                   B              C      D
    访视日期
    出生天数
    体温
      

  4.   

    如果有多条记录:
    A   B  C
    1   2   3
    4   5   6
    那么最后结果是
    c1     c2      c3
    A        1        4
    这样的三列还是下面这样的两列?
    c1     c2 
    A        1,4  
      

  5.   

    其实楼主可以用oralce的行转列函数不知道楼主的具体要求,只是这样的转换那方法还是很多也并不一定能满足楼主的真实需求
      

  6.   

    with t1 as(
     select 1 as A,2 as B,3 as C FROM DUAL
     union all
     select 4 as A,5 as B,6 as C FROM DUAL
     union all
     select 7 as A,8 as B,9 as C FROM DUAL
    ),
    t2 as(
     select 'A' as col1,(select wmsys.wm_concat(A) from t1 ) as col2 from dual
     union all
     select 'B' as col1,(select wmsys.wm_concat(B) from t1 ) as col2 from dual
     union all
     select 'C' as col1,(select wmsys.wm_concat(C) from t1 ) as col2 from dual
    )
    select col1,
    REGEXP_SUBSTR(col2,'[^,]+',1,1) AS col2,
    REGEXP_SUBSTR(col2,'[^,]+',1,2) AS col3,
    REGEXP_SUBSTR(col2,'[^,]+',1,3) AS col4,
    REGEXP_SUBSTR(col2,'[^,]+',1,4) AS col5,
    REGEXP_SUBSTR(col2,'[^,]+',1,5) AS col6
    from t2没有做排序,根据你实际要求加进去就可以。具体取多少记录你select多少列就可以。这是写死的。如果要写动态的话,单纯的sql语句实现不了