题解:最大连续回答问题天数大于等于3天的用户及其对应等级
某乎问答最大连续回答问题天数大于等于3天的用户及其对应等级
https://www.nowcoder.com/practice/e080f8a685bc4af3b47749ca3310f1fd
select b.author_id, b.author_level, max(cnt) as days_cnt from ( select a.author_id, a.author_level, count(date_result) as cnt from( select t.author_id, t.author_level, date_sub(answer_date,interval t.rk day) date_result from( select author_id, author_level, answer_date, row_number() over(partition by author_id order by answer_date) as rk #如果这里用dense_rank()就需要count(distinct answer_date)否则重复的用户无法去除,row_number()可以直接去重 from author_tb left join answer_tb using(author_id) ) t ) a group by a.author_id,a.author_level,a.date_result )b group by b.author_id,b.author_level having max(cnt)>=3 order by author_id#sql练习日常#