原创

MySQL-代码-复杂sql查询-查询考试成绩变化,或者补考次数变化

背景:
考试成绩变化,或者补考次数变化:
交卷完了不一定有成绩,这个时候拿到结果可能没有成绩,最多能拿到补考次数,
下次如果成绩变化,sql会再次命中。
还要可选关联exam_supplement ,可能有重复,需要选择最小的id

EXPLAIN
SELECT
s.id,
em.id,
em.enterprise_id,
em.work_id,
em.score,
em.user_id,
supple_time,
sign_picture_url,
photograph_picture_url,
exam_school_report_url,
em.face_url,
em.photo_url,
em.face_score,
em.face_standard,
em.face_pass
FROM
exam_marking em
INNER JOIN edu_user_online_exam_status es ON es.exam_id = em.work_id
AND es.user_id = em.user_id
AND es.container_id = em.enterprise_id
LEFT JOIN exam_supplement s ON s.exam_id = em.work_id
AND s.user_id = em.user_id
AND s.enterprise_id = em.enterprise_id
WHERE
(
es.score <> em.score
OR (
s.answer_time > UNIX_TIMESTAMP( es.update_time )
AND s.id IN ( SELECT MIN( id ) AS id FROM exam_supplement GROUP BY enterprise_id, exam_id, user_id )
)
)
AND em.is_delete = 0
AND es.is_delete = 0;

正文到此结束
本文目录