题解 | #试卷发布当天作答人数和平均分#
试卷发布当天作答人数和平均分
https://www.nowcoder.com/practice/5b58e89556dc4153a79d8cf8c08ba499
首先确定select后的字段为exam_id,count(distinct uid),avg(score),在这里首先确定uv计算的人数需要去重所以用distinct关键字,其次确定score的空置不影响avg函数计算所以不对空置做任何处理。
其次题目中给出了三个表,通过对三个表的观察,确定from后的字段为三表关联查询,找到关联字段消除笛卡尔积。
再次,确定where后的条件为‘SQL’试卷,试卷发布当天,五级以上用户
最后用group by分组。
select exam_id,
count(distinct uid) uv,
round(avg(score),1) avg_score
from exam_record er
left join user_info ui
using(uid)
left join examination_info ei
using(exam_id)
where tag='SQL'
and date_format(start_time,'%Y%m%d')=date_format(release_time,'%Y%m%d')
and level>5
group by exam_id;
