前言

查询某个部门和其子部门

SELECT dept_id 
FROM sys_dept 
WHERE dept_id = #{deptId} or find_in_set(#{deptId}, ancestors)

查询某个部门所在部门树的根节点

select dept_id 
from sys_dept 
where parent_id=0 
    and FIND_IN_SET(dept_id ,(select concat(ancestors, ',', dept_id) from sys_dept where dept_id=#{deptId}))
Logo

快速构建 Web 应用程序

更多推荐