<?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.njcn.mapper.excelreport.GetDistortionMapper">
    <select id="getDistortionData" resultType="ReportValueData">
        select phasic_type phaseType,max(${str}_THD_MAX) fmaxValue,min(${str}_THD_MIN) minValue,round(avg(${str}_THD) ,2)
        meanValue,max(case when ${str}THDCP95 =#{conditionData.count} then ${str}_THD else null end)
        cp95Value from ( select t.*,row_number() over (partition by phasic_type order by ${str}_THD desc) ${str}THDCP95
        from
        <choose>
            <when test="conditionData.b == true">
                Data_${str}
            </when>
            <otherwise>
                Day_${str}
            </otherwise>
        </choose>
        t where lineid=#{conditionData.pointIndex} and phasic_type in ('A','B','C') and timeid between
        #{conditionData.start} and #{conditionData.end}
        <if test="conditionData.b == true">
            and QualityFlag = 0
        </if>
        <foreach collection="conditionData.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>