<?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.mark.mapper.MarkSubjectiveScoreMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.qmth.teachcloud.mark.entity.MarkSubjectiveScore">
        <id column="student_id" property="studentId" />
        <result column="main_number" property="mainNumber" />
        <result column="sub_number" property="subNumber" />
        <result column="exam_id" property="examId" />
        <result column="paper_number" property="paperNumber" />
        <result column="group_number" property="groupNumber" />
        <result column="group_score" property="groupScore" />
        <result column="main_score" property="mainScore" />
        <result column="score" property="score" />
        <result column="uncalculate" property="uncalculate" />
    </resultMap>
    <select id="getSubjectiveVo" resultType="com.qmth.teachcloud.mark.bean.archivescore.QuestionVo">
        SELECT 
        t.main_title  title,t.main_number,t.sub_number,t.total_score score,
        count(*) studentCount,
        avg(s.score) avgScore,
        sum(case when s.score>0 then 1 else 0 end) scoreCount,
        sum(case when s.score=t.total_score then 1 else 0 end) fullScoreCount
        FROM mark_subjective_score s 
        left join mark_question t on t.exam_id=s.exam_id and t.paper_number=s.paper_number 
        and t.main_number=s.main_number and t.sub_number=s.sub_number
        WHERE
            s.student_id In
            <foreach collection="studentIds" item="item" index="index" open="(" separator="," close=")">
                #{item}
            </foreach>
        group by t.main_title,t.main_number,t.sub_number,t.total_score
        order by t.main_number,t.sub_number
    </select>
</mapper>
