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
|
2357 Discussions
|
Please Login in order to post a comment
SELECT N, CASE WHEN P IS NULL THEN 'Root' WHEN N IN (SELECT DISTINCT P FROM bst) THEN 'Inner' ELSE 'Leaf' END AS NodeType FROM bst ORDER BY N;
MS SQL SERVER left join
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 as types from BST order by n
MySQL / PostgreSQL
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 as Type from BST order by N;