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
相关推荐
oYiMiYangGuang12312 分钟前
【广告系列】流量优选
数据库
小蒜学长24 分钟前
vue家教预约平台设计与实现(代码+数据库+LW)
java·数据库·vue.js·spring boot·后端
专注VB编程开发20年36 分钟前
对excel xlsx文件格式当成压缩包ZIP添加新的目录和文件后,OpenXml、NPOI、EPPlus、Spire.Office组件还能读出来吗
数据库·c#·excel
小戈爱学习1 小时前
OpenLDAP 服务搭建与配置全流程指南
服务器·数据库·oracle
俊昭喜喜里1 小时前
C#和SQL Server Management Studio的连接
服务器·数据库·c#
携欢4 小时前
Portswigger靶场之 Blind SQL injection with time delays通关秘籍
数据库·sql
FeBaby4 小时前
mysql为什么使用b+树不使用红黑树
数据库·b树·mysql
青草地溪水旁5 小时前
`mysql_query()` 数据库查询函数
数据库·mysql·c
玩转数据库管理工具FOR DBLENS5 小时前
精准测试的密码:解密等价类划分,让Bug无处可逃
数据库·单元测试·测试用例·bug·数据库开发
AAA修煤气灶刘哥5 小时前
踩完 10 个坑后,我把多表查询 + MyBatis 动态 SQL 写成了干货
java·数据库·后端