-- 获得上级及上上级
with cte as(select id,name,parent_id,0 as lvl from catelog where id = '1001'
union all
select d.id,d.name,d.parent_id,lvl + 1 from cte c inner join catelog d on c.parent_id = d.id)
select * from cte
-- 获得下级及下下级
with cte as(select id,name,parent_id,0 as lvl from catelog where id = '1001'
union all
select d.id,d.name,d.parent_id,lvl + 1 from cte c inner join catelog d on c.id = d.parent_id)
select * from cte

2531

被折叠的 条评论
为什么被折叠?



