首页 > 其他分享 >608. 树节点

608. 树节点

时间:2023-02-06 20:01:15浏览次数:62  
标签:CASE WHEN 608 节点 id SELECT

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 

 

标签:CASE,WHEN,608,节点,id,SELECT
From: https://www.cnblogs.com/luyj00436/p/17096541.html

相关文章