select T.id, IF(isnull(T.p_id), 'Root', IF(T.id in (select p_id from tree), 'Inner', 'Leaf')) Type from tree T
Mine is similar.. but not quite as succinct...
select t1.id as 'Id', (if (t1.p_id is NULL, 'Root', if ((select distinct p_id from tree where t1.id = p_id) is not NULL, 'Inner', 'Leaf'))) as 'Type' from tree as t1 order by t1.id;
@richarddia Your solution is very helpful. Thanks!
Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.