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

    <select id="getDeviceStats" resultType="org.jeecg.modules.adweb.dmp.vo.report.DeviceStatsVO">
        SELECT
        device,
        SUM(total_users) total_users,
        SUM(sessions) sessions,
        SUM(page_views) page_views
        FROM
        dmp_ga_device_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
        device
        ORDER BY
        total_users DESC,
        page_views DESC
    </select>

</mapper>