SQL例题求已完成的试卷数complete_exam_cnt---表子查询结果也可以作为select里的选择项
法一:
select count(distinct if(submit_time is not null, exam_id, null)) as complete_exam_cnt from exam_record
法二:
SELECT count(distinct exam_id and score is not null) as complete_exam_cnt#将试卷去重,同时将筛选完成的试卷 from exam_record;
法三:
select count(distinct case when score is not null then exam_id else null end) as complete_exam_cnt from exam_record ;