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

SQL递归查询

时间:2016-03-29 14:43:08      阅读:230      评论:0      收藏:0      [点我收藏+]

标签:

WITH cte AS
(
    SELECT Id,Pid,DeptName,0 AS lvl FROM Department
    WHERE Id = 2
    UNION all
    SELECT d.Id,d.Pid,d.DeptName,lvl+1 FROM cte c inner join Department d
    ON c.Pid = d.Id
)
SELECT * FROM cte

 

SQL递归查询

标签:

原文地址:http://www.cnblogs.com/shenyixin/p/5332767.html

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