SQL根据某一父节点查询所有子节点,无限

;with cte as
(
select id,ParentCategoryId from Category where id = 17
union all
select a.id,a.ParentCategoryId
from Category a join cte b on a.ParentCategoryId = b.id
where a.id is not null
)

select * from cte

posted @ 2017-07-17 16:09  evemen  阅读(815)  评论(0编辑  收藏  举报