题解 | #未完成率较高的50%用户近三个月答卷情况#
未完成率较高的50%用户近三个月答卷情况
http://www.nowcoder.com/practice/3e598a2dcd854db8b1a3c48e5904fe1c
需要注意tag SQL 和 level>=67不能同时筛选,现有tag SQL排好序之后,选择好50%,再筛选等级,整个uid应该并列关系where uid IN AND IN
SELECT uid, DATE_FORMAT(start_time,'%Y%m') start_month, COUNT(start_time) total_cnt, COUNT(score) complete_cnt FROM( SELECT uid,start_time,score, DENSE_RANK() OVER (PARTITION BY uid ORDER BY DATE_FORMAT(start_time,'%Y%m') DESC) rn2 FROM exam_record) t3 WHERE rn2<=3 AND uid IN( SELECT uid FROM( SELECT uid, PERCENT_RANK() OVER (ORDER BY com_rate ASC) as rn1 FROM (SELECT uid,COUNT(submit_time)/ COUNT(start_time) AS com_rate FROM exam_record WHERE exam_id IN (SELECT exam_id FROM examination_info WHERE tag='SQL') GROUP BY uid ) AS t1 ) t2 WHERE rn1<=0.5 ) AND uid IN (SELECT uid FROM user_info WHERE `level`>=6) GROUP BY uid,start_month ORDER BY uid ASC,start_month ASC;