Mysql 逻辑语句

1、第一种写法

select id, 
case
    when p_id is null then "Root"
    when id not in (select distinct p_id from Tree where p_id is not null) then "Leaf"
    else "Inner"
end as type    // 为该列起别名
from Tree

 

2、第二种写法(case后面有表达式;值1、值2等为固定值)

 

3、第三种写法

posted @ 2023-11-03 14:55  先娶国王后取经  阅读(8)  评论(0编辑  收藏  举报