<?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.unis.examine.modular.neassessmentScore.mapper.BizNeAssessmentScoreMapper">
    <select id="selectMyMapsPage" resultType="com.unis.examine.modular.neassessmentScore.entity.VO.BizNeAssessmentScoreVO">
        SELECT
        id assessmentTargetId,
        target_no,
        score,
        MAX(CASE WHEN pc_type = '2' THEN score ELSE '' END) AS 'XNscore',
        MAX(CASE WHEN pc_type = '2' THEN deduction ELSE '' END) AS 'XNdeduction',
        MAX(CASE WHEN pc_type = '2' THEN reasonForDeduction ELSE '' END) AS 'XNreasonForDeduction',

        MAX(CASE WHEN pc_type = '3' THEN score ELSE '' END) AS 'HDcore',
        MAX(CASE WHEN pc_type = '3' THEN deduction ELSE '' END) AS 'HDdeduction',
        MAX(CASE WHEN pc_type = '3' THEN reasonForDeduction ELSE '' END) AS 'HDreasonForDeduction',

        MAX(CASE WHEN pc_type = '4' THEN score ELSE '' END) AS 'HBZcore',
        MAX(CASE WHEN pc_type = '4' THEN deduction ELSE '' END) AS 'HBZdeduction',
        MAX(CASE WHEN pc_type = '4' THEN reasonForDeduction ELSE '' END) AS 'HBZreasonForDeduction',

        MAX(CASE WHEN pc_type = '5' THEN score ELSE '' END) AS 'HXZscore',
        MAX(CASE WHEN pc_type = '5' THEN deduction ELSE '' END) AS 'HXZdeduction',
        MAX(CASE WHEN pc_type = '5' THEN reasonForDeduction ELSE '' END) AS 'HXZreasonForDeduction',

        MAX(CASE WHEN pc_type = '6' THEN score ELSE '' END) AS 'HNZscore',
        MAX(CASE WHEN pc_type = '6' THEN deduction ELSE '' END) AS 'HNZdeduction',
        MAX(CASE WHEN pc_type = '6' THEN reasonForDeduction ELSE '' END) AS 'HNZreasonForDeduction',

        MAX(CASE WHEN pc_type = '7' THEN score ELSE '' END) AS 'HNNZscore',
        MAX(CASE WHEN pc_type = '7' THEN deduction ELSE '' END) AS 'HNNZdeduction',
        MAX(CASE WHEN pc_type = '7' THEN reasonForDeduction ELSE '' END) AS 'HNNZreasonForDeduction',

        MAX(CASE WHEN pc_type = '8' THEN score ELSE '' END) AS 'GLZscore',
        MAX(CASE WHEN pc_type = '8' THEN deduction ELSE '' END) AS 'GLZdeduction',
        MAX(CASE WHEN pc_type = '8' THEN reasonForDeduction ELSE '' END) AS 'GLZreasonForDeduction',

        MAX(CASE WHEN pc_type = '9' THEN score ELSE '' END) AS 'YSZscore',
        MAX(CASE WHEN pc_type = '9' THEN deduction ELSE '' END) AS 'YSZdeduction',
        MAX(CASE WHEN pc_type = '9' THEN reasonForDeduction ELSE '' END) AS 'YSZreasonForDeduction'
        FROM  (SELECT DISTINCT
        tar.id,
        tar.target_no,
        bas.pc_type,
        tar.score,
        bas.deduction,
        bas.reason_for_deduction reasonForDeduction
        FROM

        biz_ne_assessment_target tar

        LEFT JOIN   biz_ne_assessment_manage nam on  tar.assessment_manage_id  = nam.id
        LEFT JOIN biz_ne_assessment_score bas ON bas.assessment_target_id  = tar.id
        <if test="ew.sqlSegment != null and ew.sqlSegment != ''">
            where ${ew.sqlSegment}
        </if>

        ORDER BY bas.pc_type
        )  x
        GROUP BY  id,target_no

    </select>

</mapper>