leetcode 608 樹節點
樹節點
select id, 'Root' as Type from tree where p_id is 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 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
select id, case when id = (select id from tree where p_id is null) then 'Root' when id in (select p_id from tree) then 'Inner' else 'Leaf' end as Type from tree as t order by id
select id, if(isnull(p_id), 'Root', if(id in (select p_id from tree), 'Inner','Leaf')) as Type from tree order by id
==

浙公网安备 33010602011771号