经典困难题 | #未完成率较高的50%用户近三个月答卷情况#

未完成率较高的50%用户近三个月答卷情况

https://www.nowcoder.com/practice/3e598a2dcd854db8b1a3c48e5904fe1c

select uid, start_month, total_cnt, complete_cnt
from
(select t.uid uid, date_format(start_time, '%Y%m') start_month, count(t.uid) total_cnt, count(score) complete_cnt, rank() over (partition by t.uid order by date_format(start_time, '%Y%m') desc) r
from
(select uid, count(uid) - count(score) incomplete_cnt, count(uid) total_cnt,
percent_rank() over (order by ((count(uid) - count(score)) / count(uid))) incomplete_rate
from exam_record r
left join examination_info i
on r.exam_id = i.exam_id
where tag = 'SQL'
group by uid) t
left join user_info u
on t.uid = u.uid
left join exam_record e
on t.uid = e.uid
where (level = 6 or level = 7) and incomplete_rate >= 0.5
group by t.uid, start_month) a
where r <= 3
order by uid, start_month;

使用percent_rank()排名窗口函数筛选未完成率较高的前50%用户。

全部评论

相关推荐

牛至超人:把哈工大,再加大加粗,看见闪闪发光的哈工大字样,面试官直接流口水
投递字节跳动等公司6个岗位
点赞 评论 收藏
分享
冲鸭2024:亚信不去也罢
投递亚信科技(中国)有限公司等公司6个岗位
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务