easy understanding mysql solution
\nselect id, (\n    CASE \n        WHEN p_id IS NULL THEN \'Root\'\n        WHEN id IN(select t.p_id from Tree t) THEN \'Inner\'\n        ELSE \n        \'Leaf\
```\nselect id, (\n    CASE \n        WHEN p_id IS NULL THEN \'Root\'\n        WHEN id IN(select t.p_id from Tree t) THEN \'Inner\'\n        ELSE \n        \'Leaf\'\n    END\n) AS type\nFROM Tree order by id asc;\n```\nPlease do upvote if you really like this solution.
['MySQL']