Your DDL seems not to be matching the inserts.
Below SQLs should do
CREATE SET TABLE TEST123 (
PARENT VARCHAR(20) CHARACTER SET LATIN NOT CASESPECIFIC,
CHILD VARCHAR(20) CHARACTER SET LATIN NOT CASESPECIFIC,
LVL VARCHAR(50) CHARACTER SET LATIN NOT CASESPECIFIC,
COMMON_KEY VARCHAR(20)
)
PRIMARY INDEX INUP00_CATEGY_FUNC ( PARENT, CHILD );
INSERT INTO TEST123('WS', NULL, 0,'RRT');
INSERT INTO TEST123('WS', 'WG1', 1,'RRT');
INSERT INTO TEST123('WS','WG2', 1,'RRT');
INSERT INTO TEST123('WS', 'WA', 1,'RRT');
INSERT INTO TEST123('WG1', 'W1', 2,'RRT');
INSERT INTO TEST123('WG1', 'B1', 2,'RRT');
INSERT INTO TEST123('WG2', 'W2', 2,'RRT');
INSERT INTO TEST123('WG2', 'B2', 2,'RRT');
create volatile table rn123
as
(
select parent,child,lvl,row_number() over (order by lvl,parent,child) as id
from test123
) with data
unique primary index (id)
on commit preserve rows
;
with recursive base ( id, string) as
(select id, cast(parent as varchar(100))
from rn123
where id = 1
UNION ALL
Select n.id, b.string !! ' ' !! n.child
from rn123 n
join
base b
on b.id + 1 = n.id
)
select string
from base
where (select max(id) from rn123) = id
Result:
string
WS WA WG1 WG2 B1 W1 B2 W2
If you really need
WS WG1 WG2 WA W1 B1 W2 B2
you need to explain the order rule here...
↧