题解 | #月均完成试卷数不小于3的用户爱作答的类别#
月均完成试卷数不小于3的用户爱作答的类别
https://www.nowcoder.com/practice/b1d13efcfa0c4ecea517afbdb9090845
select tag,count(1) as tag_cnt from (select distinct uid from (select uid ,count(submit_time)over(partition by uid,date_format(start_time,'%Y-%m')) as cnt from exam_record) a where cnt>=3) a join exam_record using(uid) join examination_info using(exam_id) group by tag order by tag_cnt desc
该题的题目不是很好理解,先根据示例梳理一下题目的意思
“当月均完成试卷数”不小于3的用户们” 首先这个当月就很有迷惑性,当月完成试卷数3,也就是 group by uid,年月 ,进行分组,计数>=3,来筛选出满足的完成试卷数>=3的用户uid
我们可以看到1002用户在7月份答题1次完成0次,9月份答题3次完成3次,所以在9月份中它是符合用户,除此之外还有1005用户也在9月份符合
“当月均完成试卷数”不小于3的用户们爱作答的类别及 【作答次数】,这个作答次数是,满足条件用户的所有作答记录,比如1002用户在7月份答题1次, tag 分组聚合即可