ms sql solution easy
SELECT ID as id,\nCASE \n WHEN P_ID IS NULL THEN \'Root\'\n WHEN id IN (SELECT p_id FROM Tree) THEN \'Inner\'\n ELSE \'Leaf\'\n END AS type.\n FROM TREE
SELECT ID as id,\nCASE \n WHEN P_ID IS NULL THEN \'Root\'\n WHEN id IN (SELECT p_id FROM Tree) THEN \'Inner\'\n ELSE \'Leaf\'\n END AS type.\n FROM TREE
[]