Mysql easy solution with left join
\n# Write your MySQL query statement below\nSELECT DISTINCT t1.id,\n    (CASE WHEN t1.p_id IS NULL THEN \'Root\'\n    WHEN t2.id IS NULL THEN \'Leaf\'\n    ELSE
```\n# Write your MySQL query statement below\nSELECT DISTINCT t1.id,\n    (CASE WHEN t1.p_id IS NULL THEN \'Root\'\n    WHEN t2.id IS NULL THEN \'Leaf\'\n    ELSE \'Inner\' END) Type\nFROM tree t1\nLEFT JOIN tree t2\nON t1.id = t2.p_id\nORDER BY t1.id\n```
[]