题解 | #统计作答次数#

统计作答次数

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

全部评论

相关推荐

萧索X:写篮球联赛干嘛,陪老板打篮球吗。还有实习经历要写自己所在岗位具体完成什么工作,自己的任务具体完成了什么需求,给公司带来了哪些量化增长
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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