with nodes
as (
select * from users as child where child.id = 6
union all
select par.* from users as par
inner join nodes as rc on par.id = rc.pid
)
select * from users where id in (
select id from nodes n
)
-- //
with nodes
as (
select * from users as par where par.id = 2
union all
select child.* from users as child
inner join nodes as rc on child.pid = rc.id
)
select * from users where id in (
select id from nodes n
)
原文地址:https://www.cnblogs.com/chenliang-zibo/p/9167097.html
时间: 2024-10-15 02:33:31