oracle/sqlserver 递归

1.Oracle递归查询

 2.SqlServer递归查询

复制代码
 with cte as 
 ( 
 select t.id,t.name,t.parentId from dbo.Department t where t.id='2' 
 union all  
 select k.id,k.name,k.parentId  from dbo.Department k inner join cte c on c.id = k.parentId 
 )select * from cte 
复制代码

 转自:http://www.cnblogs.com/hesheng/archive/2012/08/09/2630708.html

posted @ 2014-09-29 15:03  柠檬绿松  阅读(240)  评论(0编辑  收藏  举报
View Code