Binary Tree Nodes

  • + 0 comments

    MS SQL - With join

    WITH Parents AS ( SELECT DISTINCT P FROM BST )

    select b.N, case when b.P is null then 'Root' when b2.P IS NULL THEN 'Leaf' else 'Inner' end from BST as b left join (select P from parents ) as b2 on b.N = b2.P order by b.N