mysql根据某层部门ID查询所有下级多层子部门

SELECT dept_id, simple_name FROM
(
SELECT t1.dept_id, t1.simple_name, IF(FIND_IN_SET(pid, @pids) > 0, @pids := CONCAT(@pids, ',', dept_id), 0) AS ischild
FROM
(SELECT dept_id, pid, simple_name FROM sys_dept t ORDER BY pid, dept_id) t1,
(SELECT @pids := 1303172963761045505) t2
)
t3
WHERE ischild != 0

 

==========================================================================================================

PS:还是没有完全看懂,自测通过,先用着再说;

参考链接:

https://blog.csdn.net/Scoful/article/details/106441476

=》Mysql根据某层部门ID查询所有下级多层子部门

 

posted @ 2020-09-27 16:09  暹罗siam  阅读(3633)  评论(2编辑  收藏  举报