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
相关推荐
小白不想白a2 分钟前
【MySQL】MySQL的安全风险与安装安全风险
linux·数据库·mysql·安全
折翼的恶魔9 分钟前
SQL148 返回产品名称和每一项产品的总订单数
数据库
技术不支持21 分钟前
Qt Creator 11.0.3 语法高亮bug问题
java·服务器·数据库·qt·bug
止水编程 water_proof1 小时前
MySQL——增删改查操作
数据库·mysql
葵野寺3 小时前
【MySQL】MySQL索引—B树/B+树
数据库·b树·mysql·b+树
隔壁老登3 小时前
解决dbeaver连接不上oceanbase数据库的问题
数据库·oceanbase
····懂···4 小时前
抢占先机,PostgreSQL 中级专家认证的职业跃迁
数据库·postgresql
GBASE4 小时前
“G”术时刻:南大通用GBase 8c典型运维场景-扩缩容场景快速定位性能瓶颈
数据库
Elastic 中国社区官方博客4 小时前
用于 UBI 的 Elasticsearch 插件:从搜索查询中分析用户行为
大数据·数据库·elasticsearch·搜索引擎·全文检索
小白不想白a4 小时前
【MySQL安全】什么是SQL注入,怎么避免这种攻击:前端防护、后端orm框架、数据库白名单
数据库·sql·mysql·安全