SQL Server CLEAN & EASY
\nSELECT id, \n    CASE \n        WHEN p_id IS NULL THEN \'Root\'\n        WHEN id IN (SELECT DISTINCT p_id FROM Tree) THEN \'Inner\'\n        ELSE \'Leaf\'\n  
```\nSELECT id, \n    CASE \n        WHEN p_id IS NULL THEN \'Root\'\n        WHEN id IN (SELECT DISTINCT p_id FROM Tree) THEN \'Inner\'\n        ELSE \'Leaf\'\n    END AS type\nFROM Tree;\n```
[]