题解 | #统计作答次数#

统计作答次数

https://www.nowcoder.com/practice/45a87639110841b6950ef6a12d20175f

# 1.单表查询,关键在于对题意的理解
# total_pv计算:count(start_time)
# complete_pv计算:count(submit_time)
# 从submit_time is not null 的试卷中计算:complete_exam_cnt: distinct count(exam_id) 是错的,因为这样会把没有完成的试卷也算上,所以需要用到case when进行筛选。
# 还有一个方法,就是加一个子查询来筛选出submit_time is not null 的exam_id

select count(start_time) as total_pv,
count(submit_time) as complete_pv,
count(distinct case when submit_time is not null then exam_id
else null end) as complete_exam_cnt
from exam_record

全部评论

相关推荐

不愿透露姓名的神秘牛友
07-08 13:15
点赞 评论 收藏
分享
07-01 13:37
门头沟学院 Java
steelhead:不是你的问题,这是社会的问题。
点赞 评论 收藏
分享
评论
1
1
分享

创作者周榜

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