tree node best solution
select id,\ncase when p_id is null then \'Root\'\nwhen  id not in (select distinct p_id from Tree where p_id is not null )then \'Leaf\'\nelse \'Inner\'\nend as 
select id,\ncase when p_id is null then \'Root\'\nwhen  id not in (select distinct p_id from Tree where p_id is not null )then \'Leaf\'\nelse \'Inner\'\nend as type\nfrom Tree
[]