题解 | #试卷发布当天作答人数和平均分#
试卷发布当天作答人数和平均分
https://www.nowcoder.com/practice/5b58e89556dc4153a79d8cf8c08ba499
select er.exam_id, count(distinct ui.uid) as uv, round(sum(score) / count(submit_time),1) as avg_score from exam_record er join user_info ui using(uid) where ui.level>5 and exam_id in #筛选出当天有作答记录的试卷id (select exam_id from exam_record join examination_info using(exam_id) where DATE_FORMAT(submit_time,'%Y%m%d') = DATE_FORMAT(release_time,'%Y%m%d') and tag="SQL") group by er.exam_id order by uv DESC,avg_score
不明白为什么这样可以通过,如果现在有一个人A,A是五级以上,但是A并没有在试卷发布当天做该试卷,而有B在试卷发布当天做了,那么这套试卷的id就会被查询出来,后续只需要在筛选做这个试卷的人的等级就可以了,那么A不是被误算进来了嘛?