题解 | #连续两次作答试卷的最大时间窗#

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

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

select
uid
,count(submit_time) exam_complete_cnt
from 
(select uid
,submit_time
,dense_rank()over(partition by uid order by date_format(start_time,'%Y%m')desc) r
    from exam_record) r
    where r<=3
    group by uid
    having count(submit_time)=count(uid)
    order by 2 desc,1 desc

这里要注意到为什么 date_format(start_time)而不是submit_time,因不能给空值排名,用having count(submit_time)=count(uid)巧妙的解决null值的问题。


全部评论

相关推荐

11-15 18:39
已编辑
西安交通大学 Java
全村最靓的仔仔:卧槽,佬啥bg呢,本也是西交么
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务