|
根据指定节点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;
复制代码
|
|