LEFT JOIN ( SELECT ID_CARD, count( id ) AS count FROM ic_resi_vaccine WHERE DEL_FLAG = '0' AND CUSTOMER_ID = #{customerId} GROUP BY ID_CARD ) b ON a.ID_CARD = b.ID_CARD
LEFT JOIN ( SELECT ID_CARD, count( id ) AS count FROM ic_nat WHERE DEL_FLAG = '0' AND CUSTOMER_ID = #{customerId} GROUP BY ID_CARD ) c ON a.ID_CARD = c.ID_CARD
LEFT JOIN (
SELECT ID_CARD, count( id ) AS count
FROM ic_resi_vaccine
WHERE DEL_FLAG = '0' AND CUSTOMER_ID = #{customerId}
<iftest="startDate != null and startDate != ''">
AND DATE_FORMAT(INOCULATE_TIME,"%Y-%m-%d") > #{startDate}
</if>
<iftest="endDate != null and endDate != ''">
AND DATE_FORMAT(INOCULATE_TIME,"%Y-%m-%d") < #{endDate}
</if>
GROUP BY ID_CARD ) b ON a.ID_CARD = b.ID_CARD
LEFT JOIN (
SELECT ID_CARD, count( id ) AS count
FROM ic_nat
WHERE DEL_FLAG = '0' AND CUSTOMER_ID = #{customerId}
<iftest="startDate != null and startDate != ''">
AND DATE_FORMAT(NAT_TIME,"%Y-%m-%d") > #{startDate}
</if>
<iftest="endDate != null and endDate != ''">
AND DATE_FORMAT(NAT_TIME,"%Y-%m-%d") < #{endDate}
</if>
GROUP BY ID_CARD ) c ON a.ID_CARD = c.ID_CARD
WHERE
a.DEL_FLAG = '0'
<iftest="customerId != null and customerId != ''">
LEFT JOIN ( SELECT ID_CARD, count( id ) AS count,created_time FROM ic_nat WHERE DEL_FLAG = '0' AND CUSTOMER_ID = #{customerId} GROUP BY ID_CARD ) c ON a.ID_CARD = c.ID_CARD
WHERE a.DEL_FLAG = '0'
<iftest="customerId != null and customerId != ''">
AND a.CUSTOMER_ID = #{customerId}
</if>
<iftest="agencyId != null and agencyId != ''">
AND (AGENCY_ID = #{agencyId} OR PIDS LIKE concat( '%', #{agencyId}, '%' ))
</if>
<iftest="gridId != null and gridId != ''">
AND GRID_ID = #{gridId}
</if>
) t
WHERE 1=1
<iftest="startDate != null and startDate != ''">
AND date_format(created_time,'%Y%m%d') >= #{startDate}
</if>
<iftest="endDate != null and endDate != ''">
AND date_format(created_time,'%Y%m%d') <![CDATA[ <= ]]> #{endDate}
LEFT JOIN ( SELECT ID_CARD, count( id ) AS count,created_time FROM ic_resi_vaccine WHERE DEL_FLAG = '0' AND CUSTOMER_ID = #{customerId} GROUP BY ID_CARD ) b ON a.ID_CARD = b.ID_CARD
WHERE a.DEL_FLAG = '0'
<iftest="customerId != null and customerId != ''">
AND a.CUSTOMER_ID = #{customerId}
</if>
<iftest="agencyId != null and agencyId != ''">
AND (AGENCY_ID = #{agencyId} OR PIDS LIKE concat( '%', #{agencyId}, '%' ))
</if>
<iftest="gridId != null and gridId != ''">
AND GRID_ID = #{gridId}
</if>
) t
WHERE 1=1
<iftest="startDate != null and startDate != ''">
AND date_format(created_time,'%Y%m%d') >= #{startDate}
</if>
<iftest="endDate != null and endDate != ''">
AND date_format(created_time,'%Y%m%d') <![CDATA[ <= ]]> #{endDate}