✔️ MySQL solution
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```mysql []\n# Write your MySQL query statement below\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']