select dept_id from ( select t1.dept_id,t1.parent_id, if(find_in_set(parent_id, @pids) > 0, @pids := concat(@pids, ',', dept_id), 0) as ischild from ( select dept_id,parent_id from sys_dept t where t.del_flag = '0' order by parent_id, dept_id ) t1, (