SQLQuokka
Start practicing
QuestionsLearnSandboxFeaturesRoadmapFAQ

Classify Tree Nodes

Unsolved

A category tree stores each node with the id of its parent in p_id; root nodes have a NULL p_id. A node is 'Root' if it has no parent, 'Inner' if it has a parent and at least one child, and 'Leaf' if it has a parent and no children. A root with no children is still 'Root'. The table can contain more than one tree. Write an SQL query that returns id and node_type for every node. Order the results by id ascending.

SQL Query Editor (Ctrl+Enter to run)
0 characters · Valid
Canonical Solution Official

Official Solution is Hidden

Try solving the question with the schema explorer and hints first. When ready, reveal the verified canonical query and step-by-step logic breakdown.

Community Q&A & Discussion

Ask questions, share alternate queries, and explore solutions

0 comments
Asked By:
Classic pattern · not tied to a specific company

Submission History

Your recent query executions and answer checks

Execution Pipeline:
FROM tree
Full source dataset
6 rows total
Ready. Type a query to see live execution.
Clause: Auto-Sync · AlaSQL Engine