题解 | #统计作答次数#

统计作答次数

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

分析题目

题目条件:

三个概念,已完成,未完成,已做答的题目

初始提交版本:只利用了字段exam_id

select total_pv ,complete_pv,complete_exam_cnt
from (select count(exam_id) as total_pv from  exam_record) e1,
(select count(exam_id) as complete_pv from  exam_record  where submit_time is not null
or score is not null ) e2,
(select count(distinct exam_id) as complete_exam_cnt from  exam_record where submit_time is not null
or score is not null ) e3

改进:根据条件选取不同字段

1.利用count(null)=0 和if(条件,表达式1,表达式2)的知识点可以化子查询为更简洁的句子

count(distinct(if(submit_time is null,null,exam_id ))) as complete_exam_cnt from  exam_record
全部评论

相关推荐

我见java多妩媚:大外包
点赞 评论 收藏
分享
1 收藏 评论
分享
牛客网
牛客企业服务