本题考察点包括分组聚合、去重计数、多表连接、子查询、日期函数的使用等,也是较为综合的题目,同样根据代码梳理思路:
select t1.exam_id,count(distinct t1.uid) uv,round(avg(score),1) avg_score   //   ④ 查询所需字段,求人数时需进行去重操作,此处使用distinct;另外需要对分数求均值并保留一位小数
    from exam_record t1 left join user_info t2 on t1.uid=t2.uid 
                           left join examination_info t3 on t1.exam_id = t3.exam_id   //  ① 此处有一个很重要的点是选对主表,由于后续查询主要是利用exam_record表中的信息,因此使用exam_record表作为主表;
    where tag = "SQL" and date(release_time) = date(submit_time) and t1.uid in (select uid from user_info where level > 5)   //  ② 筛选条件包括仅查询SQL类的答题情况;完成日期为发布日期;用户等级大于5
        group by t1.exam_id   //  ③ 根据试卷id进行分组
        order by uv desc,avg_score asc   //  ⑤  最后根据答题人数、分数均值进行排序
答题过程中出现的一些问题:
由于数据来源来自三个表,各个表中包含部分相同字段,因此在选择字段时需要在前面加上相应的表名,避免查询过程中产生歧义。