题解 | #统计作答次数#

统计作答次数

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
全部评论

相关推荐

不愿透露姓名的神秘牛友
07-01 17:13
想去,但是听说加班强度实在难崩,所以拒绝了,现在有点心梗对面hr感觉也是实习生,打电话的时候怪紧张的,但是感觉人很好嘞
水中水之下水道的鼠鼠:哥们这不先去体验一下,不行再跑呗,大不了混个实习经历(有更好的转正offer就当我没说)
点赞 评论 收藏
分享
水墨不写bug:疑似没有上过大学
点赞 评论 收藏
分享
后来123321:别着急,我学院本大二,投了1100份,两个面试,其中一个还是我去线下招聘会投的简历,有时候这东西也得看运气
无实习如何秋招上岸
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

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