[SQL문제풀기] Binary Tree Nodes

silver's avatar
Apr 15, 2025
[SQL문제풀기] Binary Tree Nodes

문제

MySQL, Oracle, MS SQL Server, DB2

내가 작성한 정답

select n, case when p is null then 'Root' when n in (select p.n from bst p left join bst d on p.n = d.p where d.n is null) then 'Leaf' else 'Inner' end tree from bst order by n;

내가 작성한 정답 2

select n, case when p is null then 'Root' when n not in (select p from bst where p is not null) then 'Leaf' else 'Inner' end tree from bst order by n;
Share article

silver