mysql的辅助查询,根据学生得分字段判断老师是否完成批阅

        SELECT
        DISTINCT t.ID, IFNULL(reviewNum,0) reviewNum
        ,IFNULL(leftOverNum,0) leftOverNum
        , CASE WHEN t.status ='10E' THEN '10E'/*'已发布'*/
        WHEN t.status ='10U'  THEN '10U'/*'未开始'*/
        WHEN t.status ='10R' THEN '10R' /*'进行中'*/
        WHEN t.status is NULL THEN NULL/*'未派发'*/
        WHEN IFNULL(reviewNum, 0) = 0  THEN 'N'/*'无学生数据'*/
        WHEN IFNULL(leftOverNum, 0) = 0  THEN '10N'/*'未公布成绩'*/
        WHEN IFNULL(leftOverNum, 0) >= IFNULL(reviewNum, 0)  THEN '10F'/*'未批阅'*/
        ELSE '10I'/*'批阅中'*/
        END STATUS
        , t.NAME, t.START_TIME, t.END_TIME,  t.SUB_ID, t.EXAM_ID, t.IS_DELETE, t.CREATE_TIME, t.CREATE_USER,  t.REMARK_ON_SPOT
        , t2.SUBJECT_NAME
        FROM exp_examine t
        LEFT JOIN exp_subject t2 ON t.SUB_ID=t2.ID
        LEFT JOIN (
        SELECT b1.EXAMINE_ID , SUM(1) reviewNum, SUM(ndone) leftOverNum
        FROM (
        SELECT t1.COURSE_ID, t1.STU_ID
        , CASE WHEN SUM(CASE WHEN t1.SCORE_NUM = -1 THEN 0 ELSE 1 END)  = SUM(1)  THEN 0 ELSE 1 END ndone
        FROM exp_score_record t1
        GROUP BY  t1.COURSE_ID, t1.STU_ID
        )  b2  JOIN exp_course b1  ON  b1.ID = b2.COURSE_ID GROUP BY b1.EXAMINE_ID
        ) c1 ON t.ID = c1.EXAMINE_ID
        LEFT JOIN exp_mark_arrange_end EMAE ON EMAE.EXAMINE_ID = t.ID
        <where>
            <if test="expExamineVO.id != null  ">
                and t.ID = #{expExamineVO.id}
            </if>
            <if test="expExamineVO.name != null and expExamineVO.name != ''  ">
                t.NAME LIKE "%"#{expExamineVO.name}"%"
            </if>
            <if test="expExamineVO.startTime != null  ">
                and t.START_TIME = #{expExamineVO.startTime}
            </if>
            <if test="expExamineVO.endTime != null  ">
                and t.END_TIME &lt;= #{expExamineVO.endTime}
            </if>
            <if test="expExamineVO.subId != null  ">
                and t.SUB_ID = #{expExamineVO.subId}
            </if>
            <if test="expExamineVO.examId != null  ">
                and t.EXAM_ID = #{expExamineVO.examId}
            </if>
            <if test="expExamineVO.isDelete != null  ">
                and t.IS_DELETE = #{expExamineVO.isDelete}
            </if>
            <if test="expExamineVO.createTime != null  ">
                and t.CREATE_TIME = #{expExamineVO.createTime}
            </if>
            <if test="expExamineVO.createUser != null  ">
                and t.CREATE_USER = #{expExamineVO.createUser}
            </if>
            <if test="expExamineVO.status != null and status != ''  ">
                and t.STATUS = #{expExamineVO.status}
            </if>
            <if test="expExamineVO.remarkOnSpot != null  ">
                and t.REMARK_ON_SPOT = #{expExamineVO.remarkOnSpot}
            </if>
            <if test="userId != null">
              AND EMAE.TEACHER_ID = #{userId}
            </if>
        </where>
        <if test="expExamineVO.page != null and expExamineVO.page.orderBy != null and expExamineVO.page.orderBy != ''">
            order by ${expExamineVO.page.orderBy}
        </if>

首先有张成绩表用来记录学生每个得分 这是主表,其他从表不展示了

表的主键,课程编号,学生编号,选项编号,评分老师编号,成绩得分,评分时间

思路:

1.首先按照【学生】,【课程】分组查询学生是否已经被批阅了 node都为0表示已经被批阅过了,(这里是一个学生可能对应好几个评分项->很多的题目)

    SELECT t1.COURSE_ID, t1.STU_ID
        , CASE WHEN SUM(CASE WHEN t1.SCORE_NUM = -1 THEN 0 ELSE 1 END)  = SUM(1)  THEN 0 ELSE 1 END ndone
        FROM exp_score_record t1
        GROUP BY  t1.COURSE_ID, t1.STU_ID

2.可以根据课程进行分类,获取当前班级还有多少人未批阅完成

SELECT
        r.COURSE_ID, r.COURSE_ID reviewId, s.SOURCE_GROUP_DEF_ID seatId, r.SCORE_USER_ID  teacherId
        ,s.GROUP_ID, s.SOURCE_ID,  r.STU_ID  studentId, u.REALNAME teacherName,stu.REALNAME student_name ,stu.USERNAME exam_account,
        IFNULL(reviewNum,0) reviewNum
        ,IFNULL(leftOverNum,0) leftOverNum , CASE
        WHEN IFNULL(reviewNum, 0) = 0  THEN '无学生数据'
        WHEN IFNULL(leftOverNum, 0) = 0  THEN '批阅完成'
        WHEN IFNULL(leftOverNum, 0) >= IFNULL(reviewNum, 0)  THEN '未批阅'
        ELSE '批阅中' END judge_status
        FROM exp_score_record r
        LEFT JOIN source_group s ON s.COURSE_ID = r.COURSE_ID AND s.REAL_STUDENT_ID = r.STU_ID
        LEFT JOIN USER u ON u.ID = r.SCORE_USER_ID
        LEFT JOIN USER stu ON stu.id = r.STU_ID
        JOIN (  SELECT b2.course_id, b1.EXAMINE_ID , SUM(1) reviewNum, SUM(ndone) leftOverNum
        FROM (
        SELECT t1.COURSE_ID, t1.STU_ID
        , CASE WHEN SUM(CASE WHEN t1.SCORE_NUM = -1 THEN 0 ELSE 1 END)  = SUM(1)  THEN 0 ELSE 1 END ndone
        FROM exp_score_record t1
        GROUP BY  t1.COURSE_ID, t1.STU_ID
        )  b2  JOIN exp_course b1  ON  b1.ID = b2.COURSE_ID GROUP BY b1.EXAMINE_ID
        ) t5 ON t5.course_id = r.COURSE_ID

猜你喜欢

转载自blog.csdn.net/weixin_38289196/article/details/81113573