Neat and Easy Solution for students
IntuitionThe approach involves categorizing each node in the Tree table based on its p_id :A node is Root if p_id IS NULL, meaning it has no parent.
A node is L
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
The approach involves categorizing each node in the Tree table based on its p_id :

A node is **Root** if p_id IS NULL, meaning it has no parent.
A node is **Leaf** if its id is not present in any p_id, meaning it has no children.
Otherwise, the node is **Inner**, as it has both a parent and at least one child.

# Code
```postgresql []
-- Write your PostgreSQL query statement below
SELECT id, 
  CASE WHEN p_id IS NULL THEN 'Root' 
  WHEN id NOT IN (SELECT p_id FROM Tree WHERE p_id IS NOT NULL) THEN 'Leaf'
  ELSE 'Inner' END as type 
FROM Tree
```
['PostgreSQL']