Hi Ashish,
I think its explained above by emilwu, one can use recursive queries to achieve the concatenation
heres another example-
Assuming that tb1 is the table conataining your data
create multiset volatile table tb1
(id integer
,nm varchar(5)
) primary index (id,nm) on commit preserve rows;
insert into tb1 values (10,'xy');
insert into tb1 values (10,'yz');
insert into tb1 values (10,'zx');
insert into tb1 values (20,'ab');
insert into tb1 values (20,'bc');
create multiset volatile table tb3
as
(
sel
id
,nm
,rank () over (partition by id order by nm) rn1
from
tb1
) with data primary index (id,nm) on commit preserve rows;
with recursive rslt (id,nm,rn1,lvl)
as(
sel
id,
cast ( nm as varchar(20)),
rn1,
0 as lvl
from
tb3
where
rn1 = 1
union all
sel
rslt.id,
rslt.nm || ',' ||b.nm,
b.rn1,
rslt.lvl +1 as lvl
from
tb3 b
inner join
rslt
on
rslt.id = b.id
where
rslt.rn1 < b.rn1
)
sel id,nm
from rslt
qualify rank() over (partition by id order by lvl desc ) = 1;
Let me know if this helps
Regards
R.Rajeev
Hi Ashish,
I think its explained above by emilwu, one can use recursive queries to achieve the concatenation
heres another example-
Assuming that tb1 is the table conataining your data
create multiset volatile table tb1
(id integer
,nm varchar(5)
) primary index (id,nm) on commit preserve rows;
insert into tb1 values (10,'xy');
insert into tb1 values (10,'yz');
insert into tb1 values (10,'zx');
insert into tb1 values (20,'ab');
insert into tb1 values (20,'bc');
create multiset volatile table tb3
as
(
sel
id
,nm
,rank () over (partition by id order by nm) rn1
from
tb1
) with data primary index (id,nm) on commit preserve rows;
with recursive rslt (id,nm,rn1,lvl)
as(
sel
id,
cast ( nm as varchar(20)),
rn1,
0 as lvl
from
tb3
where
rn1 = 1
union all
sel
rslt.id,
rslt.nm || ',' ||b.nm,
b.rn1,
rslt.lvl +1 as lvl
from
tb3 b
inner join
rslt
on
rslt.id = b.id
where
rslt.rn1 < b.rn1
)
sel id,nm
from rslt
qualify rank() over (partition by id order by lvl desc ) = 1;
Let me know if this helps
Regards
R.Rajeev