题解 | 最大连续回答问题天数大于等于3天的用户
某乎问答最大连续回答问题天数大于等于3天的用户及其对应等级
https://www.nowcoder.com/practice/e080f8a685bc4af3b47749ca3310f1fd
# 字段:author_id,author_level,days_cnt
# tb1:过程表,链接
with tb1 as(
select answer_date,author_id,author_level
from answer_tb left join author_tb using(author_id)
),
# tb2:排序
tb2 as(
select author_id,author_level,dense_rank()over(partition by author_id order by answer_date) as cnt
from tb1
)
# tb3:结果表筛选天数大于等于3
select author_id,author_level,max(cnt) as days_cnt
from tb2
group by author_id,author_level
having max(cnt) >= 3