题解 | #0级用户高难度试卷的平均用时和平均得分#

0级用户高难度试卷的平均用时和平均得分

https://www.nowcoder.com/practice/bb474c6cbd77478fb6d9fc86934d0ebb

select uid, round(avg(score),0) as avg_score, round(avg(time),1) as avg_time_took from
(select er.uid, ei.exam_id,
(case when er.score is not null then er.score else 0 end ) as score, 
(case when er.submit_time is not null then timestampdiff(minute,start_time, submit_time) else ei.duration end ) as time 
from exam_record as er 
left join examination_info as ei on er.exam_id = ei.exam_id
where uid in 
(select uid from user_info
where level = 0)
and ei.exam_id in
(select exam_id from examination_info
where difficulty = 'hard')) as a
group by uid

最里层底表:

  1. where uid in +where exam_id in 筛选等级为0的用户和难度为困难的考卷
  2. case when 处理分数为空值 和提交时间为空值的试卷
  3. 只需链接exam_record和exam_info

外层表

  1. 完成两个avg汇总计算,group by uid
全部评论

相关推荐

牛客60022193...:大厂都招前端,他们觉得AI能替代前端,可能他们公司吊打btaj吧
点赞 评论 收藏
分享
2025-12-05 12:12
门头沟学院 Java
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务