데이터 분석/SQL 연습문제

Binary Tree Nodes (HackerRank)

중급닌자 연습생 2022. 11. 3. 20:53
 

Binary Tree Nodes | HackerRank

Write a query to find the node type of BST ordered by the value of the node.

www.hackerrank.com

Write a query to find the node type of Binary Tree ordered by the value of the node. Output one of the following for each node:

풀이

제출한 답

select N, (case 
           when p is null then 'Root'
           when N in (select p from bst) then 'Inner'
           else 'Leaf' end)
from bst
order by N

-> P에 있는 값이 N에도 있으면 Inner

2022.11.03