题解 | #近三个月未完成试卷数为0的用户完成情况#

近三个月未完成试卷数为0的用户完成情况

https://www.nowcoder.com/practice/4a3acb02b34a4ecf9045cefbc05453fa

with table1 as (
    select uid , 
    date_format(start_time,'%Y%m') as time,
    submit_time,
    dense_rank() over(partition by uid order by date_format(start_time,'%Y%m') desc) as time_rank
    from exam_record
),
table2 as (
    select uid ,
    sum(if(time is not null , 1 , 0)) as exam_all_cnt,
    sum(if(submit_time is not null , 1 , 0)) as exam_complete_cnt
    from table1 
    where time_rank <= 3
    group by uid
    having exam_complete_cnt = exam_all_cnt
)

select uid , exam_complete_cnt
from table2
order by exam_complete_cnt desc ,uid desc

全部评论

相关推荐

点赞 1 评论
分享
牛客网
牛客企业服务