SQL根据指定节点ID获取所有父级节点和子级节点
根据指定节点ID获取所有父节点
with temp as(
select * from dbo.Category where Id=493 --表的主键ID
union all
select t.* from temp,dbo.Category t where temp.Pid=t.Id --父级ID=子级ID
)select * from temp order by Level;
根据指定节点ID获取所有子节点
with temp as(
select * from dbo.Category where Id=344 --表的主键ID
union all
select t.* from temp,dbo.Category t where temp.Id=t.Pid --子级ID==父级ID
)select * from temp;
页:
[1]