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}