码迷,mamicode.com
首页 > 数据库 > 详细

SQL2005的cte递归查询子树

时间:2015-10-21 15:37:05      阅读:205      评论:0      收藏:0      [点我收藏+]

标签:

;with cte
as(
select id,caption,parentid,1 Gen from skywfflow where parentid =0
UNION ALL
select a.id,a.caption,a.parentid,cte.gen+1 Gen from skywfflow a
 inner join cte on a.parentid=cte.id
)
select * from cte

SQL2005的cte递归查询子树

标签:

原文地址:http://www.cnblogs.com/hz-blog/p/4897763.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!