Binary Tree Nodes

  • + 0 comments

    with cte_tree as ( select distinct a.n as node from bst a join bst b on a.n=b.p )select (case when p is null and n in (select * from cte_tree) then concat(convert(varchar(4),n),' Root') when n in (select * from cte_tree) then concat(convert(varchar(4),n),' Inner') else concat(convert(varchar(4),n),' Leaf') end) as num from bst order by n