题解 | #月均完成试卷数不小于3的用户爱作答的类别#

月均完成试卷数不小于3的用户爱作答的类别

http://www.nowcoder.com/practice/b1d13efcfa0c4ecea517afbdb9090845



select e2.tag as tag,count(*) as tag_cnt
from exam_record e1 
right join examination_info e2
on e1.exam_id=e2.exam_id
where e1.uid in 
(
    select uid
    from exam_record
    where submit_time is not null
    group by uid 
    having count(*)/count(distinct month(start_time))>=3
) 
group by e1.exam_id
order by tag_cnt desc








#第一步:筛选出月均完成大于3的用户,月均完成数目=总共完成的数目/月份的数目


select e2.tag as tag,count(*) as tag_cnt
from exam_record e1 
right join examination_info e2
on e1.exam_id=e2.exam_id
where e1.uid in 
(
    select uid
    from exam_record
    where submit_time is not null
    group by uid 
    having count(*)/count(distinct month(start_time))>=3
) 
group by e1.exam_id
order by tag_cnt desc

##
##
# SELECT ei.tag,count(er.uid) tag_cnt from exam_record er
# LEFT JOIN examination_info ei
# on er.exam_id=ei.exam_id
# WHERE uid in
# (    
#     select t.uid FROM
#     (
#         select uid,DATE_FORMAT(submit_time,'%Y-%m') month 
#         from exam_record
#         where submit_time is not null
#     ) t
#      group by t.uid
#      having count(t.uid)/count(DISTINCT t.`month`)>=3
# )
# group by ei.tag
# order by tag_cnt desc
















全部评论
select tag,count(tag) tag_cnt from exam_record left join examination_info using(exam_id) where uid in (select uid from exam_record where score is not null group by uid,date_format(start_time, '%Y-%m') having count(*)>2) group by tag order by tag_cnt desc;
点赞 回复 分享
发布于 2022-09-01 22:27 北京

相关推荐

已老实求offer😫:有点像徐坤(没有冒犯的意思哈)
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务