Binary Tree Nodes

  • + 0 comments

    if in case column (N) dosent have all the required values.

    with tbl1 as (select distinct(N) from bst), tbl2 as (select distinct(P) from bst), tbl3 as ( Select N from tbl1 union Select P from tbl2), tbl4 as ( select * from tbl3 where N is not null)

    Select *, Case when tbl4.N in (Select * from tbl2 where P in (select N from BST where P is not null)) then "Inner" when tbl4.N in (Select N from BST where P is null)then "Root" ELSE 'Leaf' end as node_type from tbl4 order by N