我们说我有这张桌子:
date | has_login
------------------------
2015-01-01 | 1
2015-01-02 | 1
2015-01-03 | 0
2015-01-04 | 1
2015-01-05 | 1
2015-01-06 | 1
2015-01-07 | 0
2015-01-08 | 1
如何获得最多的连续登录? 在这种情况下,它应该 3
答案 0 :(得分:0)
试
select max(cons) as max_consecutives
from
(
select @cons := case when has_login = 1
then @cons + 1
else 1
end as cons
from your_table
cross join (select @cons := 0) c
order by date
) tmp