题解 | #月均完成试卷数不小于3的用户爱作答的类别#
月均完成试卷数不小于3的用户爱作答的类别
https://www.nowcoder.com/practice/b1d13efcfa0c4ecea517afbdb9090845
select
-- 3.最后聚合
b.tag
,count(1) tag_cnt
from (
-- 1.要找到当月月均做题量>=3的人,就要先根据月份、用户进行分组,计算每人每月做题量。
-- 这里的目的只是找出我们要的uid
select
uid
,month(start_time) my_month
,count(submit_time) cnt
from exam_record
group by uid,month(start_time)
) a
inner join (
-- 2.把两个原始表合并得到全部想要的数据,
-- 这步之后我们已经得到了我们目标用户的全部做题数据,之后聚合、排序一下就可以了
select
t1.uid
,t2.tag
from exam_record t1
inner join examination_info t2
on t1.exam_id = t2.exam_id
) b
on a.uid = b.uid
-- 筛选做题量>=3的当月数据(这里题目没说明白,当月是9月)
where a.cnt>=3 and my_month = 9
group by b.tag
-- 4.排序
order by count(1) desc
顺丰集团工作强度 274人发布