SQL140 未完成率top50%用户近三个月答卷情况

SQL140 未完成率top50%用户近三个月答卷情况

sql 复制代码
# 请统计SQL试卷上未完成率较高的50%用户(对所有用户的完成率进行排序,找出完成率排名小于等于 50% 的用户)中,
# 6级和7级用户在有试卷作答记录的近三个月中,每个月的答卷数目和完成数目。
# 按用户ID、月份升序排序。
with
    temp1 as (
        select
            user_info.uid,
            count(if(submit_time is null, 1, null)) / count(*) as incomplete_rate
        from
            exam_record
            join user_info using (uid)
        where
            exam_id in (
                select
                    exam_id
                from
                    examination_info
                where
                    tag = 'SQL'
            )
        group by
            uid
        order by
            uid desc
    ),
    temp2 as (
        select
            uid,
            incomplete_rate,
            percent_rank() over (
                order by
                    incomplete_rate desc
            ) as pr
        from
            temp1
        order by
            pr
    ),
    temp3 as (
        select
            uid,
            date_format(start_time, "%Y%m") as start_month,
            count(start_time) as total_cnt,
            count(submit_time) as complete_cnt
        from
            exam_record
            join user_info using (uid)
        where
            uid in (
                select
                    uid
                from
                    temp2
                where
                    pr <= 0.5
            )
            and uid in (
                select
                    uid
                from
                    user_info
                where
                    level in (6, 7)
            )
        group by
            uid,
            date_format(start_time, "%Y%m")
    )
select
    uid,
    start_month,
    total_cnt,
    complete_cnt
from
    (
        select
            uid,
            start_month,
            total_cnt,
            complete_cnt,
            rank() over (
                partition by
                    uid
                order by
                    start_month desc
            ) as rk
        from
            temp3
    ) as t1
where
    rk <= 3
order by
    uid,
    start_month
相关推荐
嘻哈baby26 分钟前
Redis高可用部署与集群管理实战
数据库·redis·bootstrap
DolphinDB智臾科技1 小时前
DolphinDB 面向金融交易与定价的统一数据模型
数据库·时序数据库
檀越剑指大厂2 小时前
时序数据库性能之战:金仓数据库如何在复杂场景下反超 InfluxDB?
数据库·时序数据库
计算机毕设VX:Fegn08952 小时前
计算机毕业设计|基于springboot + vue图书借阅管理系统(源码+数据库+文档)
数据库·vue.js·spring boot·后端·课程设计
数据与人2 小时前
mongodb报错Sort exceeded memory limit of 104857600 bytes
数据库·mongodb
程序员鱼皮2 小时前
消息队列从入门到跑路,保姆级教程!傻子可懂
数据库·程序员·消息队列
C++业余爱好者2 小时前
SQL语言家族入门指南:标准SQL、T-SQL与PL/SQL详解
数据库·sql
白驹过隙^^2 小时前
OB-USP-AGENT安装使用方法
数据库·经验分享·网络协议·tcp/ip·github·ssl
计算机程序设计小李同学2 小时前
基于Python的在线零食购物商城系统的设计与实现
数据库·sqlite
Java爱好狂.3 小时前
Java面试Redis核心知识点整理!
java·数据库·redis·分布式锁·java面试·后端开发·java八股文