1. 程式人生 > >mysql 遞迴查詢所有的子節點

mysql 遞迴查詢所有的子節點

<select id="findDto" resultMap="EmployeeDtoMap" parameterType="e="java.lang.Integer" >
" >
select * from (
select a.*, *, b.name as as department_name
from t_employee a left join t_department b on on a.department_idt_id = = b.id

) x
<where>
is_deleted = 0
<if test="id != null">
and id = #{id,jdbcType=INTEGER}
</if>
<if test="code != null">
and code = #{code,jdbcType=VARCHAR}
</if>
<if test="employeeName != null">
and name like concat('%',#{employeeName},'%')
</if>
<if test="departmentId != null">
and (department_id = #{departmentId,jdbcType=VARCHAR}
or department_id in (
select id from (
select ct t1.id,
,
if(find_in_set(parent_id, @pids) > 0, @pids := concat(@pids, ',', id), 0) as ischild
from (
select id,parent_id from t_department t where re t.is_del_deleted = 0
order by parent_id, id
) t1,
(select @pids := #{departmentId,jdbcType=VARCHAR}) t2
) t3 where ischild != 0
))
</if>

</where>
<if test="order != null">
order by ${order}
</if>
</select>