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

递归
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

猜你喜欢

转载自blog.csdn.net/hezudao25/article/details/52875140