리트코드(LeetCode) SQL 문제풀이 - 608. Tree Node
2023. 1. 23. 20:09ㆍ코딩테스트/리트코드(LeetCode) - SQL Study Plan
MySQL 문제 608. Tree Node
select id,'Root' as type
from Tree
where p_id IS NULL
union
select id,'Leaf' as type
from Tree
where id NOT IN (select distinct p_id from Tree
where p_id IS NOT NULL)
AND p_id IS NOT NULL
union
select id,'Inner' as type
from Tree
where id IN (select distinct p_id from Tree
where p_id IS NOT NULL)
AND p_id IS NOT NULL
728x90
'코딩테스트 > 리트코드(LeetCode) - SQL Study Plan' 카테고리의 다른 글
리트코드(LeetCode) SQL 문제풀이 - 175. Combine Two Tables (0) | 2023.01.23 |
---|---|
리트코드(LeetCode) SQL 문제풀이 - 176. Second Highest Salary (0) | 2023.01.23 |
리트코드(LeetCode) SQL 문제풀이 - 1795. Rearrange Products Table (0) | 2023.01.22 |
리트코드(LeetCode) SQL 문제풀이 - 1965. Employees With Missing Information (0) | 2023.01.22 |
리트코드(LeetCode) SQL - 1527. Patients With a Condition (0) | 2023.01.06 |