SELECT SUM(a.t) FROM (
SELECT COUNT(1) 't' FROM xx.cpn_cover_active WHERE startAt >= #{startAt} AND
#{endAt}>=startAt AND isDelete=0
<if test="activeKey != null">
AND `key` != #{activeKey}
</if>
UNION ALL
SELECT COUNT(1) 't' FROM xx.cpn_cover_active WHERE endAt >= #{startAt} AND
#{endAt}>=endAt AND isDelete=0
<if test="activeKey != null">
AND `key` != #{activeKey}
</if>
) a
</select>
<select id="countIncludingCount" parameterType="map" resultType="int">
SELECT COUNT(1) FROM xx.cpn_cover_active WHERE #{startAt} >= startAt AND
endAt >= #{endAt} AND isDelete=0
<if test="activeKey != null">
AND `key` != #{activeKey}
</if>
</select>