select sdDept.id from ( select sd.id dept_id, sd.dept_index from sys_dept_emp sde left join sys_dept sd on (sd.id = sde.dept_id and sd.del_state = 0 and sd.dept_state = 0) where sde.emp_id = #{createEmpId} and sde.company_id = #{companyId} ) temp left join sys_dept sdDept ON (sdDept.id = temp.dept_id and sdDept.del_state = 0 and sdDept.dept_state = 0) where sdDept.dept_index like CONCAT('%',temp.dept_index,'%') and sdDept.company_id = #{companyId}
SQL案例自用
2021/12/6 11:07:37