step1:按用户分组最近一次未签到日期;

step2:当前日期减去最近一次未签到日期,即为连续签到的天数;

step3:按用户id排序。

select t.user_id, datediff('2021-06-13', m_date) as continuous_days

from (

select user_id, max(sign_date) as m_date

from user_sign_tb

where if_sign = 0

group by user_id) t

ORDER BY t.user_id;