<?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="cn.com.ctop.toutiao.modules.report.mapper.BytedanceMatReportTaskCheckInfoMapper">

    <select id="getByParams"
            resultType="cn.com.ctop.toutiao.modules.report.entity.BytedanceMatReportTaskCheckInfo">
        select a.*, a.accountCost - a.videoCost - a.imageCost as 'cc'
        from (select account.stat_datetime,
        account.advertiser_id,
        sum(account.cost)                                as 'accountCost',
        (select sum(video.cost)
        from ctop_bytedance_report_material_daily video
        where video.stat_datetime = left(account.stat_datetime, 10)
        and video.account_id = account.advertiser_id) as 'videoCost',
        (select (case
        when sum(image.cost) is null
        then 0
        else sum(image.cost) end)
        from ctop_bytedance_report_image_daily image
        where image.stat_datetime = left(account.stat_datetime, 10)
        and image.account_id = account.advertiser_id) as 'imageCost'
        from ctop_bytedance_report_advertiser_daily account
        where account.stat_datetime &gt;= #{startDate}
        and account.stat_datetime &lt;= #{endDate}
        AND account.advertiser_id = #{accountId}
        group by account.stat_datetime
        order by account.stat_datetime) a;
    </select>
</mapper>
