Binary Tree Nodes

  • + 0 comments
    select  a.n, max(
        case when b.n is null and c.n is not null then
                'Root'
             when b.n is not null and c.n is null then
                'Leaf'
             else
                'Inner'
        end )
    from bst a
    left join bst b on a.p = b.n
    left join bst c on c.p = a.n
    group by a.n
    order by a.n ;