【易错点】
先查tag='SQL'的试卷作答未完成率高的 50%用户,再从这些用户中筛选level in(6,7)的目标用户。(不要直接上来就是tag='SQL' and level in(6,7))
【答题思路】
答题月份:date_format()
最近三个月:dense_rank() over() 对答题月份进行不跳过排名排序
完成率:count(score)/count(uid)
未完成率较高的50%用户:用percent_rank () over() 对完成率进行百分比占比排序,筛选出完成率<=0.5的用户
【具体代码】
select uid,date_format(start_time,'%Y%m') as start_month,count(uid) as total,count(score) as complete1 from( select er.*,dense_rank() over(order by date_format(start_time,'%Y%m') desc) as dranking from exam_record er right join ( select uid,percent_rank()over(order by count(score)/count(start_time)) as pranking from exam_record inner join examination_info using(exam_id) where tag='SQL' group by uid )t1 using(uid) left join user_info ui using(uid) where level in(6,7) and pranking<=0.5 )t2 where dranking<=3 group by uid,start_month order by uid,start_month