NAME USERID
张三 KB001
张三 KB002
李四 KB001
李四 KB002
李四 KB003我想用SQL实现表示如下:
NAME USERID
张三 KB001,KB002
李四 KB001,KB002,KB003谢谢!

解决方案 »

  1.   

    这两天咋都是这个问题啊。SQL> select * from a;I NAM
    - ---
    1 aa
    1 bb
    1 cc
    2 xx
    2 yy
    3 zz
    3 mm select max(substr((sys_connect_by_path(name,',')),2)) cola
     from (
     select id,name,
            rownum rnum,
            row_number() over(partition by id order by id) rn1
     from a
     )
     start with rn1=1
     connect by rnum-1=prior rnum
     group by id
    ;--------------------------------------------------------------------------------aa,bb,cc
    xx,yy
    zz,mm
      

  2.   

    楼主看看我的blog吧,好多人问这种问题:
    http://blog.csdn.net/kinglht
      

  3.   

    sys_connect_by_path oracle8不能用,可惜啊