<?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="org.jeecg.modules.adweb.dmp.mapper.GASourceMediumReportMapper">

    <select id="getSourceMediumStats" resultType="org.jeecg.modules.adweb.dmp.vo.report.SourceMediumStatsVO">
        SELECT
        type,
        SUM(total_users) total_users,
        SUM(new_users) new_users,
        SUM(sessions) sessions,
        ROUND(SUM(page_views_per_session * sessions)) page_views,
        ROUND(SUM(avg_session_duration * sessions) / SUM(sessions), 2) avg_session_duration,
        ROUND(SUM(page_views_per_session * sessions) / SUM(sessions), 2) page_views_per_session
        FROM
        adweb_dmp_ga_source_medium_report
        WHERE
        site_code = #{siteCode}
        AND (type not like '%adwebcloud%' and type not like '%advich%') AND type != ''
        <if test="start != null">
            AND date >= #{start}
        </if>
        <if test="end != null">
            AND date &lt; DATE_ADD(#{end}, INTERVAL 1 DAY)
        </if>
        GROUP BY
        type
        ORDER BY
        total_users DESC,
        avg_session_duration DESC
    </select>

</mapper>