This solution will work only on the dataset that you've mentioned. If you apply this code to another dataset it will throw up erroneous results. Here is why:
- Condition b_node IS NULL and b_Parent is NULL
b_node IS NULL and b_Parent is NULLwill always give correct result i.e. 'Root' - The conditions for 'Leaf' and 'Inner' will change depending on the dataset. let's assume 5 is not the parent root, instead it is an inner node and there is a parent node 6 above it and 6 also has a child node 7
So the table becomes
a_node a_parent b_node b_parent
1 2 2 5
2 5 5 6
3 5 5 6
4 3 3 5
5 6 6 NULL
6 NULL NULL NULL
7 6 6 NULL
1. a_node a_parent b_node b_parent
1. 1 2 2 5
2. 2 5 5 6
3. 3 5 5 6
4. 4 3 3 5
5. 5 6 6 NULL
6. 6 NULL NULL NULL
7. 7 6 6 NULL
here 2 and 3 are not nulls and will be marked as 'leaf' erroneously. A
A better solution is this case is to use CASECASE to identify those nodes in a_nodea_node which can never be a parent in a_parenta_parent since they are leaf nodes.