-
[HackerRank] Binary Tree NodesSQL 2021. 9. 23. 23:30
https://www.hackerrank.com/challenges/binary-search-tree-1/problem
Code 1
SELECT N, (CASE WHEN P IS NULL THEN "Root" WHEN N IN (SELECT P FROM BST) THEN "Inner" ELSE "Leaf" END) as R FROM BST ORDER BY N;
Code 2
SELECT N, IF(P IS NULL, 'Root', IF(B.N IN (SELECT P FROM BST), 'Inner', 'Leaf')) FROM BST AS B ORDER BY N;
'SQL' 카테고리의 다른 글
[HackerRank] Top Competitors (0) 2021.09.28 [HackerRank] Weather Observation Station 5 (0) 2021.09.23 [필기] DB - SQL쿼리 - ORM (0) 2021.07.29 [sqlalchemy] 테이블간 relationship 설정 (0) 2021.07.26 [MySQL-일기장] COUNT(*) 는 NULL을 포함한다 (0) 2021.07.22