why return 'Inner' when using when id not in (select a.p_id from tree a) then 'Leaf'


  • 0
    C
    select id,
           (case
             when p_id is NULL then 'Root'
             when id not in (select a.p_id from tree a) then 'Leaf'
             else 'Inner'
            end) as Type
    from tree
    order by id
    

    I thought the code above would be better than using the following because 1 is also in the p_id but it is a root.
    case
    when p_id is NULL then 'Root'
    when id in (select a.p_id from tree a) then 'Inner'
    else 'Leaf'
    end


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.