select id,
case when p_id is null then 'Root '
when id in (select distinct p_id from tree where p_id is not null) then 'Inner'
else 'leaf' end Type
from tree
order id
select id,
case when p_id is null then 'Root '
when id in (select distinct p_id from tree where p_id is not null) then 'Inner'
else 'leaf' end Type
from tree
order id
转载于:https://www.cnblogs.com/ffeng0312/p/9829174.html