select column2 ,column3, max(substr(sys_connect_by_path(column1, ','), 2)) column1 from (
   select column2 ,column3, colc, lead(colc) over(partition by id order by colc) cold from (
   select column1,column2 ,column3, row_number() over(order by column2 ,column3) colc from tab) )
  start with cold is null
  connect by prior colc=cold
 group by column2 ,column3;

解决方案 »

  1.   

    SQL有问题:max(substr(sys_connect_by_path(column1, ','), 2)) 
    column1有问题partition by id order by colc
    id是什么?
      

  2.   

    其中列column3没什么用,只是显示出来
      

  3.   

    用自定义聚集函数比sys_connect_by_path要好
      

  4.   

    显示都乱了,我从新发一个
    column1 column2
    a        1        
    a        2        
    a        3        
    b        2        
    b        3        
    b        4        
    b        5        
    c        3        
    c        2        
    c        1        
    d        1        
    d        2        
    d        3        
    d        4        
    结果要求为
    column1 column2 
    a,c        1        
    a,c        2        
    a,c        3        
    b          2        
    b          3       
    b          4        
    b          5       
    d          1        
    d          2        
    d          3        
    d          4        
    也就是以当column2的个数和值完全相同时column1就以逗号隔开分组,如:前面的column1的a和c的column2的值都是1、2、3
    SQL 要怎么写啊??
      

  5.   

    select column2 ,column3, max(substr(sys_connect_by_path(column1, ','), 2)) column1 from (
       select column1,column2 ,column3, colc, lead(colc) over(partition by id order by colc) cold from (
       select column1,column2 ,column3, row_number() over(order by column2 ,column3) colc from tab) )
      start with cold is null
      connect by prior colc=cold
     group by column2 ,column3;
      

  6.   

    楼上的over(partition by id order by colc) cold 中的id是哪来的?有问题!看清楚我要的分组了吗?
    你那种好像是当column2相同的时候column1就以逗号分隔,
    不是我要的形式