<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.moka.gdtauto.mapper.OssFileStatisticsMapper">

    <!-- updateStatistics --> 

    <update id="updateStatistics">
    INSERT INTO oss_file_statistics
    (file_md5, cost, date, view_count, valid_click_count,ctr)
    SELECT
        pc.creative_file_md5,
        cr.cost,
        cr.date,
        cr.view_count,
        cr.valid_click_count,
        cr.ctr
    FROM req_daily_creative_report cr
            INNER JOIN ad_plan_creative pc ON cr.dynamic_creative_id = pc.creative_id
    WHERE cr.date between #{startDate} and #{endDate}
    ON DUPLICATE KEY UPDATE
   cost = VALUES(cost),
   view_count = VALUES(view_count),
   valid_click_count = VALUES(valid_click_count),
   ctr = VALUES(ctr)
    </update>
</mapper>
