UPDATE EXAM_SCORE t1
SET end_class_time = (
SELECT create_date_time
FROM (
SELECT MAX(create_date_time) AS create_date_time, exam_score_id
FROM ANSWER_RECORD t
WHERE t.exam_score_id IN (
SELECT e.id
FROM EXAM_SCORE e
WHERE e.end_class_time IS NULL
)
GROUP BY t.exam_score_id
) t2
WHERE t1.id = t2.exam_score_id
)
WHERE EXISTS (
SELECT create_date_time
FROM (
SELECT MAX(create_date_time) AS create_date_time, exam_score_id
FROM ANSWER_RECORD t
WHERE t.exam_score_id IN (
SELECT e.id
FROM EXAM_SCORE e
WHERE e.end_class_time IS NULL
)
GROUP BY t.exam_score_id
) t2
WHERE t2.exam_score_id = t1.id
)