Hello, everyone.
I have a data like this:
with t as (select 1 id, null parent_id, 2 num from dual union all
select 2, 1, 2 from dual union all
select 3, 2, 3 from dual union all
select 4, 1, 1 from dual union all
select 3, 4, 2 from dual union all
select 6, 3, 2 from dual union all
select 7, 3, 1 from dual)
as you can see the node with id = 3 is met twice.
So the tree looks like (with "num" value in square brackets)
1[2]
/ \
2[2] 4[1]
\ /
3[3;2]
/ \
6[2] 7[1]
Well, the idea is to find a query that will return the product
of "num" values of all the ancestors, including "num" value of the current node.
E.g. on the provided data the result would be:
ID PARENT_ID NUM PRODUCT
---------- ---------- ---------- ----------
1 2 2
2 1 2 4
3 2 3 12
3 4 2 4
4 1 1 2
6 3 2 24
6 3 2 8
7 3 1 12
7 3 1 4
Mention that nodes with id in (3,6,7) are returned twice because they have two different pathes to the root level.
Thanks beforehand.