<iftest="doctorOder !=null and doctorOder !=''">INNER JOIN ( SELECT SUBSTRING_INDEX( GROUP_CONCAT( id ORDER BY create_time DESC ), ',', 1 ) id FROM t_record r GROUP BY r.patient_id ) i ON tr.id = i.id</if>
<iftest="firstVisitOder!=null and firstVisitOder !=''">INNER JOIN ( SELECT SUBSTRING_INDEX( GROUP_CONCAT( id ORDER BY create_time ASC ), ',', 1 ) id FROM t_record r GROUP BY r.patient_id ) i ON tr.id = i.id</if>
LEFT JOIN t_doctor td ON tr.doctor_id = td.id
LEFT JOIN t_patient tp ON tr.patient_id = tp.id
<where>
<iftest="name != null and name != ''"> and tp.name like concat('%', #{name}, '%')</if>
<iftest="doctorId != null "> and tr.doctor_id = #{doctorId}</if>
@ -181,11 +156,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<iftest="startTime == null and endTime != '' and endTime != null "> and tr.create_time <= #{endTime}</if>
<iftest="startTime != null and endTime != null "> and tr.create_time between #{startTime} and #{endTime}</if>
</where>
) t
GROUP BY
t.patientId
<iftest="doctorOder !=null and doctorOder !=''">order by t.trCreateTime ${doctorOder}</if>
<iftest="firstVisitOder!=null and firstVisitOder !=''">order by t.tpCreateTime ${firstVisitOder}</if>
<iftest="doctorOder !=null and doctorOder !=''">order by trCreateTime ${doctorOder}</if>
<iftest="firstVisitOder!=null and firstVisitOder !=''">order by tpCreateTime ${firstVisitOder}</if>