<?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="com.utic.center.utic.stat.server.dao.mapper.UticStat15MinStatMapper">

    <insert id="insertStat15MinCenter" parameterType="java.lang.String" timeout="120">
        <![CDATA[
        INSERT INTO STAT_15MIN_CENTER_${yyMm}(STAT_DATE, LINKID, LINKLEVEL, DAY_TYPE, SPEED, TRAVEL_TIME, DATA_CNT)
        SELECT SUBSTR(#{past30Min}, 1, 12), LINKID, MIN(LINKLEVEL), MIN(DAY_TYPE),
        ROUND(AVG(SPEED)), ROUND(AVG(TRAVEL_TIME)), SUM(DATA_CNT)
        FROM STAT_5MIN_CENTER_${yyMm}
        WHERE STAT_DATE <= SUBSTR(#{past30Min}, 1, 12)
          AND STAT_DATE  > SUBSTR(#{past45Min}, 1, 12)
        GROUP BY LINKID
        ]]>
    </insert>

    <insert id="insertStat15MinLoc" parameterType="java.lang.String" timeout="120">
        <![CDATA[
        INSERT INTO STAT_15MIN_LOC_${yyMm}(STAT_DATE, LINKID, LINKLEVEL, DAY_TYPE, SPEED, TRAVEL_TIME, DATA_CNT)
        SELECT SUBSTR(#{past30Min}, 1, 12), LINKID, MIN(LINKLEVEL), MIN(DAY_TYPE),
        ROUND(AVG(SPEED)), ROUND(AVG(TRAVEL_TIME)), SUM(DATA_CNT)
        FROM STAT_5MIN_LOC_${yyMm}
        WHERE STAT_DATE <= SUBSTR(#{past30Min}, 1, 12)
          AND STAT_DATE  > SUBSTR(#{past45Min}, 1, 12)
        GROUP BY LINKID
        ]]>
    </insert>

</mapper>
