🔥🔥 Brute Force ? It works if it works :P  🔥🔥
Intuition\n Describe your first thoughts on how to solve this problem. \n##### What really seemed intuitive was grouping by p_id and use this as subquery for ou
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n##### What really seemed intuitive was grouping by p_id and use this as subquery for outer things.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n##### If an id exists in the above mentioned subquery then clearly it is either an internal node or root node. We can clearly rule out the possibility of the root by adding a not null condition to the where clause in our subquery. \n\n\n# Code\n```\nselect t1.id, \'Leaf\' as type  from tree as t1\nwhere t1.p_id and t1.id not in (select p_id as id from tree where p_id group by p_id)\n\nunion\n\nselect id,\'Root\' as type from tree where p_id is NULL\n\nunion\n\nselect t1.id, \'Inner\' as type  from tree as t1\nwhere t1.p_id and t1.id in (select p_id as id from tree where p_id group by p_id)\n```
['MySQL']