<?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.GAPagePathReportMapper">

    <select id="getPagePathStats" resultType="org.jeecg.modules.adweb.dmp.vo.report.PagePathStatsVO">
        SELECT
        *
        FROM
        (
        SELECT
        page_path,
        SUM(page_views) page_views,
        ROUND(SUM(page_views * avg_time_on_page) / SUM(page_views), 2) avg_time_on_page
        FROM dmp_ga_page_path_report
        WHERE
        site_code = #{siteCode}
        <if test="start != null">
            AND date >= #{start}
        </if>
        <if test="end != null">
            AND date &lt; DATE_ADD(#{end}, INTERVAL 1 DAY)
        </if>
        GROUP BY page_path
        ) t
        ORDER BY
        page_views DESC,
        avg_time_on_page DESC
        LIMIT #{limit}
    </select>

    <select id="countTotalPVs" resultType="java.lang.Integer">
        SELECT
        SUM(page_views) page_views
        FROM
        dmp_ga_page_path_report
        WHERE
        site_code = #{siteCode}
        <if test="start != null">
            AND date >= #{start}
        </if>
        <if test="end != null">
            AND date &lt; DATE_ADD(#{end}, INTERVAL 1 DAY)
        </if>
    </select>

</mapper>