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
|
2286 Discussions
|
Please Login in order to post a comment
SELECT N,CASE WHEN ISNULL(P) THEN "Root" WHEN N IN (SELECT P FROM BST) THEN "Inner" ELSE "Leaf" END FROM BST ORDER BY N;
Select N, Case when P is null then 'Root' when N in (Select P from BST) then 'Inner' else 'Leaf' end from BST order by N
-- Why condition for 'Leaf' must have WHERE p IS NOT NULL b/c NOT IN is entangle with NULL. If you're not write WHERE clause, the result are returned with NULL value
-- On the other hand why condition for 'Inner' no need to have WHERE clause like 'Leaf' b/c IN is not entangle with NULL. It disregard NULL
select N, case when P is null then 'Root' when N in (select P from BST) then 'Inner' else 'Leaf' END as bs from BST order by N;
SELECT N, CASE WHEN P IS NULL THEN 'Root' WHEN N IN (SELECT P FROM BST) THEN 'Inner' ELSE 'Leaf' END AS Type FROM BST ORDER BY N;