image_2022-04-28_17-14-32.png
26.5 KB
#medium
#N608. Tree Node
problem link
#solution
#N608. Tree Node
problem link
#solution
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