-
Binary Tree Nodes<HackerRank> 2023. 7. 12. 21:36728x90
Binary Tree Nodes
-- DB2, ORACLE
SELECT N,
(CASE WHEN P IS NULL THEN 'Root'
WHEN N NOT IN (SELECT NVL(P,0) FROM BST) THEN 'Leaf'
ELSE 'Inner'
END)
FROM BST
ORDER BY N;
-- MYSQL, MS SQL SERVER
SELECT N ,
CASE
WHEN p IS NULL THEN "Root"
WHEN N IN (SELECT DISTINCT P FROM BST) THEN "Inner"
ELSE "Leaf"
END
FROM BST ORDER BY N;728x90'<HackerRank>' 카테고리의 다른 글
Weather Observation Station 19 (0) 2023.07.19 Weather Observation Station 18 (0) 2023.07.17 NEW Companies (0) 2023.07.14 The PADS (0) 2023.07.10