有一张表 user
列如下:
cool1  cool2
林     A
陈     B
张     F
陈     C
张     D
张     E
林     D
---------------------------------
如何实现查询结果
cool1 cool2
林    AD
陈    BC
张    DEF
------------------------------------
多谢各位!!

解决方案 »

  1.   


    --10g以上用wm_concat函数
    select cool1,replace(wm_concat(cool2),',','') cool2
    from user
    group by cool1
    /
      

  2.   


    SQL> with t as(
      2       select '林' cool1,'A' cool2 from dual union all
      3       select '陈','B' from dual union all
      4       select '张','F' from dual union all
      5       select '陈','C' from dual union all
      6       select '张','D' from dual union all
      7       select '张','E' from dual union all
      8       select '林','D' from dual)
      9  select cool1,replace(wm_concat(cool2),',','') cool2
     10  from t
     11  group by cool1
     12  /
     
    COOL1 COOL2
    ----- ---------------------------
    陈    BC
    林    AD
    张    FDE
      

  3.   

    select cool1,replace(wm_concat(cool2),',','') cool2
    from user
    group by cool1wm_concat在10g版本以上可以用。