LEFT JOIN ( SELECT equipment_id, max( create_time ) AS min_binding_time FROM tb_wechat_equipment GROUP BY equipment_id ) min_binding ON le.id = min_binding.equipment_id
LEFT JOIN tb_wechat_equipment we ON le.id = we.equipment_id
AND we.create_time = min_binding.min_binding_time
LEFT JOIN tb_wechat_account wa ON wa.id = we.account_id
where le.user_id = #{userId}
<iftest="username != null">
AND wa.username LIKE concat('%',#{username,jdbcType=VARCHAR},'%')
</if>
<iftest="wxId != null">
AND wa.wx_id LIKE concat('%',#{wxId,jdbcType=VARCHAR},'%')
</if>
<iftest="startTime != null">
and wa.create_time >= #{startTime,jdbcType=TIMESTAMP}
</if>
<iftest="endTime != null">
and wa.create_time <= #{endTime,jdbcType=TIMESTAMP}
LEFT JOIN ( SELECT equipment_id, max( create_time ) AS min_binding_time FROM tb_wechat_equipment GROUP BY equipment_id ) min_binding ON le.id = min_binding.equipment_id
LEFT JOIN tb_wechat_equipment we ON le.id = we.equipment_id
AND we.create_time = min_binding.min_binding_time
LEFT JOIN tb_wechat_account wa ON wa.id = we.account_id