문제
Each node in the tree can be one of three types:
"Leaf": if the node is a leaf node."Root": if the node is the root of the tree."Inner": If the node is neither a leaf node nor a root node.
Write a solution to report the type of each node in the tree.
Return the result table in any order.
" Leef, Root, Inner로 분류하여라"
문제 풀이
1) Root의 경우는 p_id가 Null 인 경우이다.
2) Inner의 경우는 P-id가 id에 속해 있어야 하고, id도 역시 p_id에 속해야 있어야 한다.
3) 그 외의 경우는 leaf 이다.
SELECT id
, CASE WHEN p_id IS NULL THEN 'Root'
WHEN p_id IN (SELECT id FROM Tree) AND id IN (SELECT p_id FROM Tree) THEN 'Inner'
ELSE 'Leaf' END AS type
FROM Tree
'취준 > 코팅 테스트' 카테고리의 다른 글
[LeetCode] - 1070.Product Sales Analysis 3 (0) | 2024.04.15 |
---|---|
[LeetCode] 1084. Sales Analysis 3 (0) | 2024.04.10 |
[LeetCode] - 1965. Employees With Missing Information (0) | 2024.04.09 |
585. Investments in 2016 (0) | 2024.04.09 |
[LeetCode] - 1204. Last Person to Fit in the Bus (0) | 2024.04.06 |