logins has one row per customer per day they signed in. Questions like "what's each customer's longest streak of days in a row?" are known as gaps and islands: the islands are runs of consecutive days, the gaps are the days between. They're a favourite in interviews, and they come up for real with sessions, outages and subscriptions.
Gaps first. LAG gives the previous login day, and the difference in days says how long the gap was. Anything over 1 means at least one day was missed:
SELECT customer_id, day,
julianday(day) - julianday(LAG(day) OVER (PARTITION BY customer_id ORDER BY day)) AS gap
FROM logins
WHERE customer_id = 1
ORDER BY day;
Now islands. The trick: number each customer's days 1, 2, 3 with ROW_NUMBER, and take that number away from the date. Along a run of consecutive days, the date and the number both go up by 1, so the difference stays the same. When a day is skipped, the date jumps by 2 and the difference changes. So the difference labels each island:
SELECT customer_id, day,
ROW_NUMBER() OVER (PARTITION BY customer_id ORDER BY day) AS n,
date(day, '-' || ROW_NUMBER() OVER (PARTITION BY customer_id ORDER BY day) || ' days') AS island
FROM logins
WHERE customer_id = 1
ORDER BY day;
Group by that label and each group is one streak, with its first day, last day and length:
WITH labelled AS (
SELECT customer_id, day,
julianday(day) - ROW_NUMBER() OVER (PARTITION BY customer_id ORDER BY day) AS island
FROM logins
)
SELECT customer_id, MIN(day) AS starts, MAX(day) AS ends, COUNT(*) AS days
FROM labelled
GROUP BY customer_id, island
ORDER BY customer_id, starts;
The trick needs one row per customer per day. If the same day could appear twice, take DISTINCT days first. To list the missing days rather than the streaks, generate a calendar with a recursive CTE (last lesson) and keep the days with no login, using EXCEPT or a LEFT JOIN.
Practice
Every login with the same customer's previous login day: customer_id, day and the previous day (NULL for their first).