Simple MSSQL
select id,\n case when p_id is null then \'Root\'\n      when id in (select p_id from tree) then \'Inner\'\n      else \'Leaf\'\nend as Type\nFROM tree
select id,\n case when p_id is null then \'Root\'\n      when id in (select p_id from tree) then \'Inner\'\n      else \'Leaf\'\nend as Type\nFROM tree
[]