SQL: Tree Node

Medium
SQL — Subqueries SQL CASE Subquery
Classify tree nodes as Root, Inner, or Leaf.

Constraints

Write standard SQL (MySQL 8.0 compatible).

Examples

Example 1:
Input: id parent 1 null 2 1 3 1 4 2
Output:
Example 2:
Input: id parent 1 null 2 1 3 1 4 2
Output:

Hints

CASE with subquery on parent/child.
▲ Console

Install Talent Arabia

Get instant access to jobs and career tools on your device.