题解 | #某乎问答最大连续回答问题天数大于等于3天#

某乎问答最大连续回答问题天数大于等于3天的用户及其对应等级

https://www.nowcoder.com/practice/e080f8a685bc4af3b47749ca3310f1fd

本组最后一道题,打个卡,有两三天没做题了,就牛客自己出的题最离谱。这个题应该没有谁不会,打卡题

(用户最大连续天数,题目中没有对显示的days_cnt做具体说明,如果取用户连续最大,你自己再套一层)

select
    c.author_id,d.author_level,c.days_cnt
from 
(
    select
        b.author_id,count(distinct b.answer_date) as days_cnt
    from 
    (
        select 
            a.author_id,a.answer_date,date_sub(a.answer_date, interval (dense_rank() over(partition by a.author_id order by a.answer_date)) day) as groupDate
        from answer_tb a
    ) b group by b.author_id,b.groupDate having count(distinct b.answer_date) >= 3
) c join author_tb d on c.author_id = d.author_id
order by c.author_id

全部评论

相关推荐

shtdbb_:还不错,没有让你做了笔试再挂你
点赞 评论 收藏
分享
点赞 1 评论
分享
牛客网
牛客企业服务