USING CASE
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```\n-- Write your PostgreSQL query statement below\n\nSELECT \n    id,\n    CASE WHEN  p_id IS NULL\n        THEN\n            \'Root\'\n        ELSE\n            CASE WHEN id IN (SELECT p_id FROM Tree)\n                THEN\n                    \'Inner\'\n                ELSE\n                    \'Leaf\'\n            END\n    END AS type\nFROM Tree\n```
['PostgreSQL']