最长连续登录天数
select
distinct b.user_id,b.max_consec_days
from
(
select
a.user_id,
max(a.max_contiday) over(partition by a.user_id) as max_consec_days
from
(
select
t.user_id,
count(1) as max_contiday
from
(
select
fdate,
user_id,
day(fdate)+1-row_number() over(partition by user_id order by fdate) as conti
from tb_dau
) as t
group by t.user_id,t.conti
) as a
group by a.user_id,a.max_contiday
) as b
参考文献:https://leetcode.cn/problems/consecutive-numbers/ 具体思路见上述链接,很清晰直白,有问题请指正哈~~~

京公网安备 11010502036488号