We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
- Prepare
- SQL
- Advanced Select
- Binary Tree Nodes
- Discussions
Binary Tree Nodes
Binary Tree Nodes
Sort by
recency
|
2477 Discussions
|
Please Login in order to post a comment
This solution may be more performant for very large tables as it doesn't require the creation of a whole new DISTINCT set
MYSql Solution
SELECT N, CASE WHEN P IS NULL THEN 'Root' WHEN N IN (SELECT DISTINCT P FROM BST WHERE P IS NOT NULL) THEN 'Inner' ELSE 'Leaf' END AS NodeType FROM BST ORDER BY N;
An alternative solution
Using CTE and OUTER APPLY...
x