有一个表,内容如下
1  01
1  02
1  03
2  04
2  05
3  06
要求这样的数据结果
1 010203
2 0405
3 06请大家帮忙,谢谢

解决方案 »

  1.   

    select col1,replace(sys_connect_by_path(col2,','),',','') col2
    from (
    select col1,col2,row_number()over(partition by col1 order by col2)-dense_rank()over(order by col1) rn,min(col2)over(partition by col1) mv
    from tablename)
    start with col2=mv
    connect by  prior rn=rn-1
    group by col1
      

  2.   

    sbaz(万神渡劫)试了一下你的办法
    结果
    col1  col2
    0800 
    1
    2
    3
    不是要的结果
      

  3.   

    SQL> select * from a;         A B
    ---------- ----------
             1 01
             1 02
             1 03
             2 04
             2 05
             3 06已选择6行。SQL> select a,replace(max(sys_connect_by_path(b,';')),';','') b
      2  from (select a,b,
      3               (row_number() over(order by a,b)
      4               + dense_rank() over(order by a)) rn,
      5               min(b) over(partition by a) mb
      6        from a
      7  )
      8   start with b = mb
      9   connect by rn-1 = prior rn
     10   group by a
     11  ;         A  B
    ------------------------------------
             1  010203
             2  0405
             3  06SQL>
      

  4.   

    SQL> select * from a;         A B
    ---------- ----------
             1 01
             1 02
             1 03
             2 04
             2 05
             3 06已选择6行。SQL> select a,replace(max(sys_connect_by_path(b,';')),';','') b
      2  from (select a,b,
      3               (row_number() over(order by a,b)
      4               + dense_rank() over(order by a)) rn,
      5               min(b) over(partition by a) mb
      6        from a
      7  )
      8   start with b = mb
      9   connect by rn-1 = prior rn
     10   group by a正解,需要用分析函数
      

  5.   

    waterfirer(水清)
    佩服
    谢谢了 ,给分