zOs/SQL/PLANDAQ2
with g (quFr, quTo, cnt, quNx, coNx, l) as
(
select min(queryNo), min(queryNo), 0, min(queryNo), -9, 0
from cmnBatch.plan_table
union all select quFr, quTo, cnt, quNx
, ( select count(*) from cmnBatch.plan_table
where queryNo = quNx )
, l+1
from g where coNx=-9 and l < 999e3
union all select quFr, quNx, cnt, -6, -6, l+1
from g where coNx = 0 and l < 999e3
union all select quFr, quNx, cnt+coNx, -8, -8, l+1
from g where coNx > 0 and cnt+coNx < 1e3 and l < 999e3
union all select quFr, quTo, cnt, -7, -7, l+1
from g where coNx > 0 and cnt+coNx >= 1e3 and l < 999e3
union all select quNx, quNx, coNx, -8, -8, l+1
from g where coNx > 0 and cnt+coNx >= 1e3 and l < 999e3
union all select quFr, quTo, cnt
, ( select min(queryNo) from cmnBatch.plan_table
where queryNo > quTo )
, -9
, l+1
from g where coNx=-8 and l < 999e3
)
select *
from g
where coNx in ( -7, -6)