题解 | #根据指定记录是否存在输出不同情况#
根据指定记录是否存在输出不同情况
https://www.nowcoder.com/practice/f72d3fc27dc14f3aae76ee9823ccca6b
SELECT ui.uid, SUM(IF(score IS NULL AND start_time IS NOT NULL,1,0)) incomplete_cnt, ROUND(AVG(IF(score IS NULL AND start_time IS NOT NULL,1,0)),3) incomplete_rate from user_info ui left join exam_record er using(uid) where if((SELECT ui.uid FROM user_info as ui LEFT JOIN exam_record as er ON ui.uid = er.uid WHERE level = '0' GROUP BY ui.uid HAVING SUM(IF(score IS NULL AND start_time IS NOT NULL,1,0))>2) IS NOT NULL, level = '0', start_time IS NOT NULL) group by ui.uid order by incomplete_rate