Binary Tree Nodes

Sort by

recency

|

2286 Discussions

|

  • + 0 comments

    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;

  • + 0 comments

    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

  • + 0 comments
    SELECT
        n,
        CASE
            WHEN p IS NULL THEN 'Root'
            WHEN n IN (SELECT DISTINCT p FROM bst) THEN 'Inner'
            WHEN n NOT IN (SELECT DISTINCT p FROM bst WHERE p IS NOT NULL) THEN 'Leaf'
        END AS conditionTable
    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

  • + 0 comments

    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;

  • + 0 comments

    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;