MySQL || use CASE || 90% beats
\n\n# Code\n\nselect a.id,(\n    case\n    when a.p_id is null \n    then \'Root\' \n    when exists(select  * from Tree t where t.p_id=a.id)\n    then \'Inner\
\n\n# Code\n```\nselect a.id,(\n    case\n    when a.p_id is null \n    then \'Root\' \n    when exists(select  * from Tree t where t.p_id=a.id)\n    then \'Inner\'\n    else \'Leaf\' end\n    ) AS type\nfrom Tree a;\n```\n\n```please upvote, if you find it useful```
['MySQL']