题解 | #统计作答次数#
统计作答次数
https://www.nowcoder.com/practice/45a87639110841b6950ef6a12d20175f
select count(start_time) as total_pv, count(submit_time) as complete_pv, count(distinct if(submit_time is not null,exam_id,null)) as complete_exam_cnt from exam_record;
三个知识点:
- count(*)和count(字段)的区别,count(*)包含所有的字段,包括null和空,而count(字段)不包括null但是包括空.
- count中可以加条件
- if (exp1,exp2,exp3) 如果exp1成立,那么结果为exp2,否则结果为exp3.