Saltar al contenido
← volver

Solving the Classic SQL "Gaps and Islands" Problem: 3 Modern Approaches

DEV · dev.to · publicado 15/9/2026, 3:15:39

If you've ever needed to find consecutive streaks in data — days a user logged in back to back, uninterrupted stretches of sensor readings, runs of matching status codes — you've run into the "gaps and islands" problem. The "islands" are the consecutive runs. The "gaps" are the breaks between them. SQL doesn't have a built-in FIND_STREAKS() function, so you build it with window functions instead. Here's the sample data we'll use throughout — a table of user login dates: user_id login_date 1 202…

Leer original →