题解 | #近三个月未完成试卷数为0的用户完成情况#
近三个月未完成试卷数为0的用户完成情况
https://www.nowcoder.com/practice/4a3acb02b34a4ecf9045cefbc05453fa
不用group by having
select distinct uid, exam_complete_cnt from ( select uid, sum(if(submit_time is null, 1, 0)) over w AS uncomplete_cnt, count(submit_time) over w AS exam_complete_cnt from ( select uid, submit_time, DENSE_RANK() over( PARTITION BY uid order by date_format(start_time, '%Y%m') desc ) recent_m from exam_record ) t1 where recent_m < 4 window w AS (PARTITION BY uid) ) tmp where uncomplete_cnt = 0 order by exam_complete_cnt desc, uid desc;