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

    技术2025-02-19  71

    sql语句

    select id,name from (select t1.id,t1.name,if(find_in_set(pid, @pids) > 0,@pids := concat(@pids, ',', id),0) as ischild from(select id,pid,name from sys_dept t order by pid,id ) t1, (select @pids := #{deptId}) t2 ) t3 where ischild != 0

    #{deptId} :   你传入的部门id

    pid    :    你数据库表中部门与上级部门关联

    id   :  部门id 

     

     

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

    Processed: 0.013, SQL: 9