题解 | #0级用户高难度试卷的平均用时和平均得分#
0级用户高难度试卷的平均用时和平均得分
https://www.nowcoder.com/practice/bb474c6cbd77478fb6d9fc86934d0ebb
SELECT uid, # 计算均分,当有score的时候,就返回实际的,没有就是0 ROUND(AVG(IF(score, score, 0)), 0) avg_score, # 计算均用时,使用TIMESTAMPDIFF计算时间差,分钟为单位 ROUND(AVG(IF(score, TIMESTAMPDIFF(MINUTE, start_time, submit_time), duration)), 1) avg_time_took FROM exam_record c JOIN user_info a USING(uid) JOIN examination_info b USING(exam_id) # 限制条件 WHERE level = 0 AND difficulty = 'hard' GROUP BY uid