orders(order_id, user_id, ordered_at)
Return the user_id of everyone who ordered on three or more consecutive
calendar days during 2026, ordered by user_id.
Several orders on one day are still one day, so duplicates have to go before the consecutive check rather than after.
The usual approach is gaps and islands: subtract a row number from the date, and consecutive days collapse to the same value.
Tables
orders
order_id user_id ordered_at
-------- ------- -------------------
1 10 2026-03-01 09:00:00
2 10 2026-03-01 18:00:00
3 10 2026-03-02 09:00:00
4 10 2026-03-03 09:00:00
5 11 2026-03-01 09:00:00
6 11 2026-03-02 09:00:00
7 11 2026-03-04 09:00:00
8 12 2026-03-10 09:00:00
... 3 more row(s)
Expected result
user_id
-------
10
12