Tree Nodes as Root, Inner, or Leaf || Case Statement
Intuition:We classify tree nodes based on their parent-child relationships:
Root: No parent (p_id IS NULL).
Inner: Has a parent and also has children (id IN (SE
# Intuition:
We classify tree nodes based on their parent-child relationships:

* Root: No parent (p_id IS NULL).
* Inner: Has a parent and also has children (id IN (SELECT p_id FROM tree)).
* Leaf: Has a parent but no children.

# Approach:
1. Root: p_id IS NULL
2. Inner: p_id IS NOT NULL and id is a p_id in the table.
3. Leaf: Has a parent but no children.

# Code
```mysql []
# Write your MySQL query statement below
SELECT id,
CASE
    WHEN p_id IS NULL THEN 'Root'
    WHEN p_id IS NOT NULL AND id IN (SELECT p_id FROM tree) THEN 'Inner'
    ELSE 'Leaf'
    END AS type
FROM Tree
```
# If you understood the solution , pls upvote...

['MySQL']