题解 | #统计作答次数#

统计作答次数

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

乍一看是挺简单的一题,好像只需要计算出各个字段的count值即可,这里有一个坑,就是当没完成交卷的次数不计入计数的时候,三个字段就无法通过where去进行筛选,这里使用if对单个需要不计算非交卷的个数进行排除即可。

select 
count(*) total_pv,
count(submit_time) complete_pv,
count(distinct if(submit_time is not null, exam_id, null)) complete_exam_cnt 
from exam_record;
全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务