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
相关推荐
字符串str1 分钟前
sql的基本技术栈
数据库·sql·oracle
秦jh_16 分钟前
【Redis】客户端使用
数据库·redis·缓存
剑之所向19 分钟前
DataEase 做大屏,只认 2 种 SQL 格式
数据库·sql·正则表达式
我真会写代码26 分钟前
Redis核心特性详解:事务、发布订阅与数据删除淘汰策略
java·数据库·redis
TDengine (老段)44 分钟前
TDengine IDMP 工业数据建模 —— 数据标准化
大数据·数据库·物联网·ai·时序数据库·tdengine·涛思数据
羊小蜜.1 小时前
Mysql 01:基础查询(SELECT)全解——从单表到多字段的完整语法
数据库·mysql·查询
猿小喵1 小时前
记录一次从库并行回放出现死锁的问题
数据库·mysql·tdsql
随风,奔跑1 小时前
Redis
数据库·redis·缓存
IvorySQL1 小时前
2MB 的 PostgreSQL work_mem,如何吃掉 2TB 内存?
数据库·postgresql·开源
桑榆肖物2 小时前
有字幕,没配音?用浏览器自带语音能力,让网页视频直接“开口说话”
数据库·edge·音视频·tts