SQL2008+ 根据子类ID来查找最大级父类ID

来源:互联网 发布:希尔伯特 知乎 编辑:程序博客网 时间:2024/05/20 05:28

递归
2008可以在帮助文档搜索CTE


with cte as(  select PraentID from tb where id=@id  union all  select a.PraentID from tb a join cte b on a.ID=b.PraentID where PraentID is not null  )select * from cte

0 0
原创粉丝点击