题解 | #统计作答次数#

统计作答次数

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

# 有一个试卷作答记录表exam_record,请从中统计出总作答次数total_pv、
# 试卷已完成作答数complete_pv、已完成的试卷数complete_exam_cnt。

# 写法一:不用case when
# select count(id),count(score)
# ,(
#     select count(distinct exam_id)
#     from exam_record
# ) as complete_exam_cnt
# from exam_record

# 写法二:case when
select count(id)
,count(case when score is not null then 1 else null end )
,count(distinct CASE when score is not null then exam_id else null end)
from exam_record

全部评论

相关推荐

点赞 评论 收藏
分享
06-20 17:42
东华大学 Java
凉风落木楚山秋:要是在2015,你这简历还可以月入十万,可惜现在是2025,已经跟不上版本了
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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