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
|
2467 Discussions
|
Please Login in order to post a comment
SELECT N, CASE WHEN p IS NULL then 'Root' WHEN N IN (SELECT p FROM BST WHERE p IS NOT NULL) THEN 'Inner' else 'Leaf' end FROM BST order by N
**SELECT N, CASE WHEN P IS NULL THEN 'Root' WHEN N NOT IN (SELECT P FROM BST WHERE P IS NOT NULL) THEN 'Leaf' ELSE 'Inner' END FROM BST ORDER BY N ; **
SELECT N, CASE WHEN P IS NULL THEN 'Root' WHEN N NOT IN (SELECT P FROM BST WHERE P IS NOT NULL) THEN 'Leaf' ELSE 'Inner' END FROM BST ORDER BY N ;
select N , IF(p is NULL, 'Root', IF(N in (select p from BST where p is not NUll), 'Inner','Leaf'))
from BST order by N;