Super easy solution MySQL
Intuition\n Describe your first thoughts on how to solve this problem. \nIn this question, we find out that: \n- If a number is \'NULL\' in p_id, then it is a r
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nIn this question, we find out that: \n- If a number is \'NULL\' in **p_id**, then it is a **root** node\n- If a number appears in **both id and p_id**, it is an **inner** node\n- If a number **only appears in id and not in p_id**, it is a **leaf** node\n# Approach\n<!-- Describe your approach to solving the problem. -->\nNow using the intuition from above, we can simply use a **CASE Clause** to create a new column \'type\' to cover all three possible cases.  \n# Complexity\n- Time complexity: This is not the fastest way to solve this question but it is very easu to understand\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: N/A\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\n# Write your MySQL query statement below\nselect id, case \nwhen p_id is null then \'Root\'\nwhen p_id in (select id from tree) and id in (select p_id from tree) then \'Inner\'\nELSE \'Leaf\'\nend as type\nfrom Tree\n\n```
['MySQL']