mybatis的union查询
<select id="selectByNull" resultMap="BaseResultMap">
SELECT DISTINCT b.SAMPLE_NO,
b.ID,
b.SPECIMEN_ID,
b.RECEIVED_SPECIMEN_TIME,
b.RECEIVED_SPECIMEN_PLACE,
b.RECEIVER,
b.SENDER,
b.REMARK,
b.RECORD_STATUS,
b.CREATE_TIME,
b.MODIFY_TIME,
r.Name,
t.ASSAY_NO
FROM BIZ_SPECIMEN_LAB_RECEPTION b
LEFT JOIN BIZ_ASSAY_ORDER_SAMPLE o on o.SAMPLE_NO=b.SAMPLE_NO
LEFT JOIN RES_LABORATORY r on r.ID=o.SAMP_PREP_DEPT_CODE
LEFT JOIN BIZ_ASSAY_TASK_INFO t ON t.SAMPLE_NO=b.SAMPLE_NO
LEFT JOIN BIZ_ASSAY_ITEM_DATA d on d.SPECIMEN_ID=b.SPECIMEN_ID
WHERE 1=1
AND d.ASSAY_STATUS=0
<if test="laboratoryId!=null and laboratoryId!=''">
AND r.ID=#{laboratoryId}
</if>
<if test="sampleNo!=null and sampleNo!=''">
AND b.SAMPLE_NO=#{sampleNo}
</if>
<if test="fromDate!=null and fromDate!=''">
and <![CDATA[b.RECEIVED_SPECIMEN_TIME>=to_date(#{fromDate}, 'yyyy-mm-dd') ]]>
</if>
<if test="toDate!=null and toDate!=''">
and <![CDATA[b.RECEIVED_SPECIMEN_TIME<=to_date(#{toDate}, 'yyyy-mm-dd') ]]>
</if>
UNION
SELECT DISTINCT b.SAMPLE_NO,
b.ID,
b.SPECIMEN_ID,
b.RECEIVED_SPECIMEN_TIME,
b.RECEIVED_SPECIMEN_PLACE,
b.RECEIVER,
b.SENDER,
b.REMARK,
b.RECORD_STATUS,
b.CREATE_TIME,
b.MODIFY_TIME,
r.Name,
t.ASSAY_NO
FROM BIZ_SPECIMEN_LAB_RECEPTION b
LEFT JOIN BIZ_ASSAY_ORDER_SAMPLE o on o.SAMPLE_NO=b.SAMPLE_NO
LEFT JOIN RES_LABORATORY r on r.ID=o.SAMP_PREP_DEPT_CODE
LEFT JOIN BIZ_ASSAY_TASK_INFO t ON t.SAMPLE_NO=b.SAMPLE_NO
LEFT JOIN BIZ_ASSAY_ITEM_DATA d on d.ASSAY_TASK_INFO_ID=t.ID
WHERE 1=1
AND d.ASSAY_STATUS=0
<if test="laboratoryId!=null and laboratoryId!=''">
AND r.ID=#{laboratoryId}
</if>
<if test="sampleNo!=null and sampleNo!=''">
AND b.SAMPLE_NO=#{sampleNo}
</if>
<if test="fromDate!=null and fromDate!=''">
and <![CDATA[b.RECEIVED_SPECIMEN_TIME>=to_date(#{fromDate}, 'yyyy-mm-dd') ]]>
</if>
<if test="toDate!=null and toDate!=''">
and <![CDATA[b.RECEIVED_SPECIMEN_TIME<=to_date(#{toDate}, 'yyyy-mm-dd') ]]>
</if>
</select>