<?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.TAExamCourseTeacherDioMapper">

    <select id="findByTAExamCourseRecordDio"
            resultType="com.qmth.teachcloud.report.business.entity.TAExamCourseTeacherDio">
        SELECT
            exam_id AS examId,
            course_code AS courseCode,
            MAX(course_name) AS courseName,
            teacher_id AS teacherId,
            MAX(teacher_name) AS teacherName,
            dimension_type AS dimensionType,
            dimension_code AS dimensionCode,
            AVG(student_score) AS avgScore,
            AVG(score_rate) AS scoreRate
        FROM
            t_a_exam_course_record_dio
        <where>
            <if test="examId > 0">
                and exam_id = #{examId}
            </if>
            <if test="courseCode != null and courseCode.length > 0">
                and course_code = #{courseCode}
            </if>
        </where>
        GROUP BY exam_id , course_code , teacher_id , dimension_type , dimension_code;
    </select>
</mapper>
