sqlserver 查询一级部门

版权声明:本文为博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/weixin_42270031/article/details/83651020

WITH cte AS (
        SELECT Id, supdepid, departmentname, 0 AS lv
        FROM HrmDepartment c
        WHERE id = '当前部门id'
        UNION ALL
        SELECT d.Id, d.supdepid, d.departmentname, lv + 1
        FROM cte c
            INNER JOIN HrmDepartment d ON c.supdepid = d.Id
    )
SELECT *
FROM cte
ORDER BY cte.lv DESC

展开阅读全文

没有更多推荐了,返回首页