<?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.qmth.teachcloud.report.business.mapper.TAExamCourseCollegeInspectMapper">

    <select id="findCourseDescriptiveStatisticsForCollege" resultType="com.qmth.teachcloud.report.business.bean.result.TAExamCourseCollegeInspectResult">
        select
            so.id as collegeId,
            so.name as collegeName,
            round(convert(taecci.max_score, decimal(10, 4)), 2) as maxScore,
            round(convert(taecci.min_score, decimal(10, 4)), 2) as minScore,
            round(convert(taecci.avg_score, decimal(10, 4)), 2) as avgScore,
            taecci.reality_count as realityCount,
            taecci.absent_count as absentCount,
            taecci.total_count as totalCount,
            round(convert(taecci.upper_quartile, decimal(10, 4)), 2) as upperQuartile,
            round(convert(taecci.median, decimal(10, 4)), 2) as median,
            round(convert(taecci.lower_quartile, decimal(10, 4)), 2) as lowerQuartile,
            taecci.mode,
            round(convert(taecci.standard_deviation, decimal(10, 4)), 2) as standardDeviation,
            round(convert(taecci.relative_position, decimal(10, 4)), 2) as relativePosition
        from
            t_a_exam_course_college_inspect taecci
        join sys_org so on
            so.id = taecci.college_id
        <where>
            <if test="examId != null and examId != ''">
                and taecci.exam_id = #{examId}
            </if>
            <if test="courseCode != null and courseCode != ''">
                and taecci.course_code = #{courseCode}
            </if>
            <if test="collegeId != null and collegeId != ''">
                and taecci.college_id = #{collegeId}
            </if>
        </where>
    </select>

    <select id="findCourseDescriptiveStatisticsForSchool" resultType="com.qmth.teachcloud.report.business.bean.result.TAExamCourseCollegeInspectResult">
        SELECT
            round(convert(current_min_score,decimal(10,4)),2) AS minScore,
            round(convert(current_max_score,decimal(10,4)),2) AS maxScore,
            round(convert(current_avg_score,decimal(10,4)),2) AS avgScore,
            current_reality_count AS realityCount,
            current_absent_count AS absentCount,
            current_total_count AS totalCount,
            round(convert(current_upper_quartile,decimal(10,4)),2) AS upperQuartile,
            round(convert(current_median,decimal(10,4)),2) AS median,
            round(convert(current_lower_quartile,decimal(10,4)),2) AS lowerQuartile,
            current_mode,
            round(convert(current_standard_deviation,decimal(10,4)),2) AS standardDeviation,
            tbe.exam_time as examTime,
            tbe.exam_name as examName
        FROM
            t_a_exam_course taec
            join t_b_exam tbe
            on tbe.id = taec.exam_id
        <where>
            <if test="courseCode != null and courseCode != ''">
                and taec.course_code = #{courseCode}
            </if>
            <if test="examId != null and examId != ''">
                and taec.exam_id = #{examId}
            </if>
        </where>
    </select>
</mapper>
