sys_connect_by_path select i,ltrim(max(sys_connect_by_path(a,',')),',') afrom(select i,a,d,min(d) over(partition by i) d_min,(row_number() over(order by i,d))+(dense_rank() over (order by i)) numidfrom t)start with d=d_min connect by numid-1=prior nu