Having the following table my_tabe
:
M01 | 1
M01 | 2
M02 | 1
I want to query over it in order to obtain:
M01 | 1,2
M02 | 1
I managed to get close using the following query:
with my_tabe as
(
select 'M01' as scycle, '1' as sdate from dual union
select 'M01' as scycle, '2' as sdate from dual union
select 'M02' as scycle, '1' as sdate from dual
)
SELECT scycle, ltrim(sys_connect_by_path(sdate, ','), ',')
FROM
(
select scycle, sdate, rownum rn
from my_tabe
order by 1 desc
)
START WITH rn = 1
CONNECT BY PRIOR rn = rn - 1
Yielding:
SCYCLE | RES
M02 | 1,2,1
M01 | 1,2
Which is wrong. It's seems I'm close, but I'm afraid I don't what's the next step...
Any tips?