Given a table of ids and parent ids, write SQL to determine each id's type (Leaf, Root, or Inner). Asked in the phone screen stage. A root has no parent, an inner node has a parent and children, and a leaf has only a parent.
tree.id and type, where type is Root, Inner, or Leaf.id ascending.| Column | Type | Description |
|---|---|---|
| idPK | INT | Unique identifier for the node |
| parent_id | INT | Identifier of the node's parent, or NULL for a root |