with t (Col1, Col2, Col3, Col4) as (
select 'Ajay', 'G1', 'B1', '10.201.131.27' from dual union all
select 'Ajay', 'G1', 'B2', '10.201.131.27' from dual union all
select 'Ajay', 'G1', 'B1', '10.201.131.28' from dual union all
select 'Ajay', 'G1', 'B2', '10.201.131.28' from dual union all
select 'Ajay', 'G1', 'B1', '10.201.131.29' from dual union all
select 'Ajay', 'G1', 'B2', '10.201.131.29' from dual)
, t1 as (
select Col1, Col2
, listagg(Col3, ',') within group (order by Col3) x
, listagg(Col4, ',') within group (order by Col4) y
from t
group by Col1, Col2
)
select Col1, Col2
, rtrim(regexp_replace(x || ',', '([^,]+,)\1+', '\1'), ',') Col3_
, rtrim(regexp_replace(y || ',', '([^,]+,)\1+', '\1'), ',') Col4_
from t1
;
COL1 CO COL3_ COL4_
---- -- ------------------------------ ------------------------------------------------------------
Ajay G1 B1,B2 10.201.131.27,10.201.131.28,10.201.131.29
Я показывал это в два шага, но это может быть и в один шаг.
select Col1, Col2
, rtrim(regexp_replace(listagg(Col3, ',') within group (order by Col3) || ',', '([^,]+,)\1+', '\1'), ',') Col3_
, rtrim(regexp_replace(listagg(Col4, ',') within group (order by Col4) || ',', '([^,]+,)\1+', '\1'), ',') Col4_
from t
group by Col1, Col2
;