不连表 就是玩儿

试卷发布当天作答人数和平均分

http://www.nowcoder.com/practice/5b58e89556dc4153a79d8cf8c08ba499

select exam_id,count(distinct uid) as uv,round(avg(score),1) as avg_score
from exam_record
where exam_id in (select exam_id from examination_info where tag = 'SQL') 
      and uid in (select uid from user_info where level >5)
      and date(submit_time) in (select date(release_time) from examination_info where tag = 'SQL')
      and submit_time is not NULL
group by exam_id,date(submit_time)
order by uv desc,avg_score asc
全部评论
你这个答案明显是错的,date(submit_time) in 子查询, 子查询需要添加exam_id相等的条件才可以, 不然都不是一一对应的时间
1 回复 分享
发布于 2021-11-18 17:47
select ei.exam_id,count(distinct er.uid) as uv , round(avg(er.score),1) as avg_score from user_info as ui , examination_info as ei, exam_record as er WHERE ui.uid = er.uid and er.exam_id = ei.exam_id and DATE_format(ei.release_time, '%y-%m-%d') = DATE_format(er.submit_time, '%y-%m-%d') and ui.level > 5 and ei.tag = 'SQL' and er.submit_time is not null group by ei.exam_id order by uv desc,avg_score asc;
点赞 回复 分享
发布于 2022-02-18 11:43
select er.exam_id,count(distinct er.uid) as uv, round(avg(score),1) as avg_score from exam_record er join examination_info ei on er.exam_id=ei.exam_id where uid in(select uid from user_info where level >5) and ei.tag='SQL' and date(ei.release_time)=date(er.submit_time) group by er.exam_id order by uv desc, avg_score
点赞 回复 分享
发布于 2022-02-08 15:00
date(start_time) in (select date(release_time) from examination_info where tag ='SQL') 把submit_time换成start_time
点赞 回复 分享
发布于 2022-01-13 15:31
当天作答这么写不对吧
点赞 回复 分享
发布于 2021-11-16 17:26

相关推荐

Aurora23:属于挂一半,暂时进池子了,隔一段时间没有其他组捞的话就彻底结束了
点赞 评论 收藏
分享
评论
30
收藏
分享

创作者周榜

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