Easy to Understand | SQL
\nselect\n    id,\n    case\n        when p_id is null then \'Root\'\n        when id not in (select p_id from tree B where T.id = B.p_id) then \'Leaf\'\n      
```\nselect\n    id,\n    case\n        when p_id is null then \'Root\'\n        when id not in (select p_id from tree B where T.id = B.p_id) then \'Leaf\'\n        else \'Inner\'\n    end as type\nfrom tree T;\n```\nIf you have any **doubts**, feel **free to ask**...\nIf you understand the **concept**. Don\'t Forget to **upvote**\n\n
['MySQL']