sql server 获取指定节点的所有父节点或者所有子节点
程序员文章站
2022-06-08 09:23:16
...
sql 获取指定节点的所有父节点或者所有子节点
获取节点的所有父节点
;with
#tmp as(
select * from tb
where id = 'DMA20120327036'
union all
select a.* from tb a, #tmp b
where a.id = b.pid
)
select * from #tmp
获取节点的所有子节点
;with
#tmp as(
select * from tb
where id = 'DMA20120327036'
union all
select a.* from tb a, #tmp b
where a.pid = b.id
)
select * from #tmp
上一篇: mysql - 编译配置PHP时,两种配置写法有什么不同
下一篇: 如何使用elementui