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

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

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

having语句筛选出完成试卷数和作答试卷数相同的记录,因为这个条件意味着用户没有未完成的试卷





select uid,count(score) as  exam_complete_cnt
from 
(
    select *
    ,date_format(start_time,"%Y%m") as month
    ,dense_rank() over(partition by uid order by date_format(start_time,"%Y%m") desc) as rk 
    from exam_record
) t 
where rk <=3
group by uid
having exam_complete_cnt=count(id) 
order by exam_complete_cnt desc,uid desc




全部评论

相关推荐

gcniz:一天写两千行你闹呢
点赞 评论 收藏
分享
1 收藏 评论
分享
牛客网
牛客企业服务