+-------------+------+ | Column Name | Type | +-------------+------+ | id | int | | p_id | int | +-------------+------+ id is the primary key column for this table. Each row of this table contains information about the id of a node and the id of its parent node in a tree. The given structure is always a valid tree.
Each node in the tree can be one of three types:
"Leaf": if the node is a leaf node. "Root": if the node is the root of the tree. "Inner": If the node is neither a leaf node nor a root node. Write an SQL query to report the type of each node in the tree.
Return the result table in any order.
The query result format is in the following example.
if p_id = null then root. id p_id left join on id == p_id in this case, if the right p_id is null then it is leaf because this node is not the parent of any node. And we can use case when to assign a new column. Let's do this.
AC. This problem is medium level but actually it's easier than the yesterday's problem.