I would like to do a kind of a CTE query like one can do in MS-SQL.
The below data is representing a tree with an id and parent relation.
Code:
id parent type
1 NULL c
2 1 o
3 2 c
4 2 o
5 1 o
6 NULL c
7 6 c
8 7 c
9 7 o
10 NULL c
11 10 c
12 11 o
13 10 o
14 11 o
I want to find out the closed id. It can be himself or the next up in the tree
So when I query or sp...it should look like this.
Code:
id parent type lastclosed
1 NULL c 1
2 1 o 1
3 2 c 3
4 2 o 1
5 1 o 1
6 NULL c 6
7 6 c 7
8 7 c 8
9 7 o 7
10 NULL c 10
11 10 c 11
12 11 o 11
13 10 o 10
14 11 o 11
The query will look through the tree from the bottom to the top, it should set the lastclosed id when it sees a 'c' in the type column.