Tree structures in SQL
Suppose you have a table called 'tree' that contains a column of nodes as well as corresponding parent nodes:
Write a SQL query that will label each node as a 'root' (no parent node), 'leaf' (no child nodes), or 'inner' (contains both parent and child nodes). Given the table above, your query should return the following:
You can view/query this table in an interactive SQL fiddle here.
Subscribe to premium account to see the solution.Get premium now