mysql 递归查找所有的子节点

青春壹個敷衍的年華 提交于 2020-03-30 04:03:50

<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>

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!