608. 树节点

608. 树节点

/* Write your T-SQL query statement below */
SELECT id   , 
    (CASE WHEN p_id IS NULL THEN 'Root' ELSE       -- 根节点,p_id为null        
       CASE WHEN  id IN (SELECT p_id FROM tree)  THEN 'Inner' ELSE 'Leaf' END     -- 是否有孩子节点,若有,则内部节点,否则叶子节点
    END  )    AS type
FROM tree 
ORDER BY id 

 

posted @ 2023-02-06 19:50  陆陆无为而治者  阅读(21)  评论(0编辑  收藏  举报