suppose I have a tree data stored in mytab with id, parentid,
then I want to get all parents for each id in one query.
For example, a binary tree like(node 1 parent is null):
1
11 12
111 112 121 122
for any node, find out all parents with parent level(from bottom to top).
for example, node 111: I want to have data like:
id parentid level
111 11 1
11 1 2
for node 11, I want to have data like:
id parentid level
111 11 1
for node 121, I want to have data like:
id parentid level
121 12 1
12 1 2
and so on.
Without cursor with loop(cursor with very bad performance for this case), how to get it in one query(maybe a recursive query)?