<?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.pqs9000.mapper.report.GetVoltageMapper">
    <select id="getVoltageData" resultType="ReportValue">
        select phasic_type PHASETYPE,
        <choose>
            <when test="condition.b == true">
                MAX(FLUC) FMAXVALUE,MIN(FLUC) MINVALUE,ROUND(AVG(FLUC) ,2) MEANVALUE
                ,MAX(CASE WHEN FLUCCP95 =#{condition.count} THEN FLUC ELSE NULL END) CP95VALUE
                FROM ( SELECT T.*,
                ROW_NUMBER() OVER (PARTITION BY PHASIC_TYPE ORDER BY FLUC DESC) FLUCCP95
                from Data_fluc
            </when>
            <otherwise>
                MAX(FLUC_MAX) FMAXVALUE,MIN(FLUC_MIN) MINVALUE,ROUND(AVG(FLUC) ,2) MEANVALUE
                ,MAX(CASE WHEN FLUCCP95 =#{condition.count} THEN FLUC ELSE NULL END) CP95VALUE
                FROM ( SELECT T.*,
                ROW_NUMBER() OVER (PARTITION BY PHASIC_TYPE ORDER BY FLUC DESC) FLUCCP95
                from Day_fluc
            </otherwise>
        </choose>
        t where lineid=#{condition.pointIndex} and phasic_type in ('A','B','C') and timeid between
        #{condition.start}
        and #{condition.end}
        <if test="condition.b == true">
            and QualityFlag = 0
        </if>
        <foreach collection="condition.exceptTime" index="index" item="item" open=" " separator=" " close="">
            and timeid not between #{item.start} and #{item.end}
        </foreach>) a
        group by phasic_type
    </select>
</mapper>