SQL递归查询
Traffic_Sites 表
SiteId 本节点的id ParentId 上级节点的id
8.238
通过父节点查询所有子节点
with t as
(
select b.* from Traffic_Sites b where ParentId = '4'
union all
select a.* from Traffic_Sites a join t b on a.ParentId=b.SiteId
)
select * from t
调换 SiteId 的位置
通过子节点查询每个父级
with t as
(
select b.* from Traffic_Sites b where SiteId = '418'
union all
select a.* from Traffic_Sites a join t b on a.SiteId=b.ParentId
)
select * from t