<?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="rptZoneSqlMapper">

	<select id="findByOperatorIdAndDatAdvertiser" parameterType="map" resultType="com.cloudcross.ssp.model.RptZone">
		select operator_id as operatorId, date, sum(pv) as totalPv, sum(uv) as totalUv,
        sum(impression) as totalImpression, sum(click) as totalClick,sum(income) as totalIncome from t_rpt_zone
        where  operator_id = #{operatorId} and date=#{date}
	</select>
	
<!-- 导出excel用 -->
	<select id="findByParams1" parameterType="map" resultType="com.cloudcross.ssp.model.RptZone">
		select date, sum(impression) as impression, sum(click) as click, sum(ecpm) as ecpm,
        sum(income) as income from t_rpt_zone
        where  operator_id = #{operatorId} and date >= #{startDate} and date &lt;= #{endDate}
        <if test="zoneId!=null">
        	and zone_id = #{zoneId}
        </if>
		group by date
	</select>
		<select id="findByDate" parameterType="map" resultType="com.cloudcross.ssp.model.RptZone">
		select operator_id as operatorId, date, sum(pv) as pv, sum(uv) as uv,
        sum(impression) as impression, sum(click) as click,sum(income) as income from t_rpt_zone
        where date=#{date}
	
	
	</select>
	
	<select id="countByParams" parameterType="map" resultType="int">
		select count(id) from t_rpt_zone
        where id in ( select id from t_rpt_zone
        where  operator_id = #{operatorId} and date >= #{startDate} and date &lt;= #{endDate}  
        <if test="zoneId!=null">
        	and zone_id = #{zoneId}
        </if>      
		group by date
       		)  
	</select>
	
		<select id="findByOperatorIdAndDateOperator" parameterType="map" resultType="com.cloudcross.ssp.model.RptZone">
			select operator_id as operatorId, date, sum(pv) as pv, sum(uv) as uv,
        sum(impression) as impression, sum(click) as click,sum(income) as income from t_rpt_zone
        where  operator_id = #{operatorId} and date=#{date}
	</select>
	
		<select id="findByParams" parameterType="map" resultType="com.cloudcross.ssp.model.RptZone">
		select date, sum(impression) as impression, sum(click) as click, sum(ecpm) as ecpm,
        sum(income) as income from t_rpt_zone
        where  operator_id = #{operatorId} and date >= #{startDate} and date &lt;= #{endDate}
        <if test="zoneId!=null">
        	and zone_id = #{zoneId}
        </if>
		group by date
		limit #{pager.offset}, #{pager.limit}
	</select>
</mapper>