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
相关推荐
hong_zc1 小时前
redis之缓存
数据库·redis·缓存
诺青2352 小时前
MongoDB副本集
数据库·mongodb
正在走向自律3 小时前
金仓数据库打通电子证照国产化“最后一公里”——福建某地2TB MongoDB无缝迁移实践
数据库·mongodb·国产数据库·电科金仓
阿波罗尼亚3 小时前
复杂查询:直接查询/子查询/视图/CTE
java·前端·数据库
Go高并发架构_王工3 小时前
MySQL内存优化:缓冲池与查询缓存调优技术详解
数据库·mysql·缓存
disanleya4 小时前
mysql怎么安装,新手安装MySQL后如何安全备份不踩坑?
数据库·mysql
zhennann4 小时前
VonaJS多租户同时支持共享模式和独立模式
数据库·typescript·node.js·nestjs
打码人的日常分享4 小时前
信息化系统安全建设方案
大数据·数据库·人工智能·安全·系统安全
zuoyou-HPU4 小时前
QT中的pyodbc.connect()函数
服务器·数据库·oracle
last_zhiyin4 小时前
Oracle sql tuning guide 翻译 Part 6-3 --- 用Hint影响优化器
数据库·sql·oracle·优化器·hint