Oracle数据合并问题~~~
请问下,infocode字段重复了,然后把columnname,columncode这两个字段的值合并为成一条记录。
最后结果:001002007001003,001002007001007001
各位,大神帮帮忙~
------解决方案--------------------不要用wm_concat了,12c已经被干掉了。用listagg
------解决方案--------------------数据:
SQL> select * from test1;
A B C
---------- ---------- ----------
1 2 4
1 3 4
2 3 4
3 3 4
1 5 4
1 2 3
2 2 3
SELECT A.A,
ltrim(MAX(REPLACE(SYS_CONNECT_BY_PATH(B, '—'), '—', ',')),','),
ltrim(MAX(REPLACE(SYS_CONNECT_BY_PATH(C, '—'), '—', ',')),',')
FROM (SELECT T.*, ROW_NUMBER() OVER(PARTITION BY A ORDER BY B) AS RN
FROM TEST1 T) A
START WITH RN = 1
CONNECT BY PRIOR RN = RN - 1
AND PRIOR A = A
GROUP BY A;
结果:
1 2,2,3,5 4,3,4,4
2 2,3 3,4
3 3 4