MSSQL answer
\nSELECT id,\n       CASE\n            WHEN p_id IS NULL THEN  \'Root\'\n            WHEN id IN(SELECT p_id AS id FROM tree ) THEN \'Inner\'\n            ELSE \
```\nSELECT id,\n       CASE\n            WHEN p_id IS NULL THEN  \'Root\'\n            WHEN id IN(SELECT p_id AS id FROM tree ) THEN \'Inner\'\n            ELSE \'Leaf\'\n       END AS Type\nFROM  tree\n```\n
['MS SQL Server']