node의 타입을 구분해보자.
case when 사용하면 된다.
select id,
(case
when p_id is null then 'Root'
when id in (select p_id from tree) then 'Inner'
else 'Leaf'
end ) as type
from tree
case when 구문 안 select 절에 distinct(p_id)했는데 distinct 빼는 것이 더 빠르더라
'learning > SQL' 카테고리의 다른 글
[LeetCode 1667] Fix Names in a Table (0) | 2023.01.28 |
---|---|
[LeetCode 1527] Patients With a Condition (0) | 2023.01.28 |
[LeetCode 1965] Employees With Missing Information (0) | 2023.01.28 |
[LeetCode 196] Delete Duplicate Emails (0) | 2023.01.28 |
[LeetCode 627] Swap Salary (0) | 2023.01.28 |
댓글