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

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

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

# count不会将空值记录进去
# 计算月均完成试卷数,等于总完成试卷数/多少各月份
# t1先计算总的完成数量和总共占多少月份
with t1 as (
    select uid, 
    count(score) as total_cnt,
    count(distinct DATE_FORMAT(start_time, "%Y%m")) as month_cnt
    from exam_record 
    where score IS NOT NULL
    group by uid
),
# 找到月均完成数满足条件的用户
t2 as (
    select uid, 
    (case when month_cnt = 0 then total_cnt
    else total_cnt/month_cnt end) as month_avg
    from t1
    having month_avg >= 3
),
t3 as (
    select uid, exam_id
    from exam_record as a
    where uid in (
        select uid
        from t2
    )
)
select b.tag, count(t3.exam_id) as tag_cnt
from t3
left join examination_info as b
on t3.exam_id = b.exam_id
group by b.tag
order by tag_cnt desc;

全部评论
该题需要注意的是月均完成数=总完成数量/完成试卷的月份的个数,我刚开始最大-最小,看评论才知道
点赞 回复 分享
发布于 2023-08-16 11:44 江苏

相关推荐

12-18 22:04
已编辑
杭州电子科技大学 Java
程序员牛肉:我觉得是这样的,你现在有点病急乱投医了。你要问自己这样一个问题: 我找实习的目的是什么?为了挣钱还是增强个人实力?如果是为了挣钱那没得说,如果我是为了增强个人实习,那我异地去一个小厂实习真的有收益吗?这个收益是否大过我参加学校的项目或者自学?我记得你们杭电有那种实验室专门负责运维学校的项目的。 找实习只是一个手段而已,不要把他变成目的。不要病急乱投医。
实习简历求拷打
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务