You are viewing a single comment's thread. Return to all comments →
Using CTE and OUTER APPLY...
WITH Parents AS ( SELECT DISTINCT P FROM BST ) SELECT b.N , CASE WHEN b.P IS NULL THEN 'Root' WHEN oa.P IS NULL THEN 'Leaf' ELSE 'Inner' END FROM BST b OUTER APPLY ( SELECT b2.P FROM Parents b2 WHERE b.N = b2.P ) oa ORDER BY b.N ; go
x
Seems like cookies are disabled on this browser, please enable them to open this website
Binary Tree Nodes
You are viewing a single comment's thread. Return to all comments →
An alternative solution
Using CTE and OUTER APPLY...
x