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
相关推荐
float_六七27 分钟前
SQL预编译:安全高效数据库操作的关键
数据库·sql·安全
写代码也要符合基本法1 小时前
Oracle SQL - 使用行转列PIVOT减少表重复扫描(实例)
数据库·sql·oracle
刺客xs2 小时前
MYSQL数据库----DCL语句
android·数据库·mysql
胖墩的IT2 小时前
在高并发场景下,仅依赖数据库机制(如行锁、版本控制)无法完全避免数据异常的问题
数据库·mysql
天天爱吃肉82182 小时前
汽车嵌入式开发:如何构建「不可替代」的核心竞争力?
数据库·汽车
彬彬醤3 小时前
ChatGPT无法登陆?分步排查指南与解决方案
服务器·网络·数据库·网络协议·chatgpt
长风破浪会有时呀5 小时前
Redis 命令总结
数据库·redis·缓存
潇凝子潇5 小时前
MySQL 的 `EXPLAIN` 输出中,`filtered` 属性使用
android·数据库·mysql
lifallen5 小时前
Flink Exactly Once 和 幂等
java·大数据·数据结构·数据库·分布式·flink