Collections
Datasets
Tools
CSV to SQL
JSON to SQL
Sign In
Name
Description
Master the gaps-and-islands pattern, one of SQL's most versatile techniques for analyzing time-series data. This tutorial demonstrates how to identify continuous periods (islands) and breaks (gaps) in overlapping events, from hotel booking clusters to network alarm sequences. Learn to use window functions like LAG() and running sums with CTEs to solve real-world problems in network monitoring, user session analysis, server uptime tracking, and equipment maintenance scheduling. Includes complete working examples you can run immediately in PostgreSQL or MySQL.
Database
PostgreSQL
MySQL
MariaDB
Oracle
Cancel
Save
Use desktop for interactive SQL sandbox
Settings
Fork this book
Notes
SQL
MySQL - 8.0
Oracle - 21.3.0
PostgreSQL - 17
ERD
Run Code
Read-only book
Fork to Edit
Tip: Press
Alt
+
Enter
to run SQL
SQL Output
Clear
Getting Started
1
Switch to a SQL tab and select a database
2
Write or paste your SQL in the editor
3
Press
Alt
+
Enter
to run
Quick Templates
Show Tables
Basic SELECT
JOIN Example
Create Table
Tip:
Select text in the editor to run only that portion
sql-gaps-and-islands-problem
Updated 1/30/26, 2:23 AM
Notes
SQL
Alt+Enter to run