← 🗄️ Data & SQL EngineeringNEXT IN DATA & SQL ENGINEERINGChange Data Capture→
Core
Gaps and Islands (Sessionization)
Gaps-and-islands is the pattern for grouping consecutive rows into runs (islands) separated by breaks (gaps), the engine behind sessionization, streak detection, and consolidating contiguous ranges. The trick is to assign a group id that stays constant within a run, classically with window functions: ROW_NUMBER differences or LAG-based break flags with a running sum. Applied-AI interviews probe it because sessionizing events (user sessions, activity streaks, contiguous time ranges) is a constant data task and a sharp test of window-function fluency.
a free account unlocks the core curriculum tier · no card
COURSES COVERING THIS TOPIC
No lesson covers this one directly yet. These teach the surrounding topic from the beginning.
RELATED CONCEPTS
PRACTICE THIS IN REAL QUESTIONS
SQL & Data EngineeringGroup a stream of user events into sessions in SQL (30-minute inactivity gap) using window functions.→SQL & Data EngineeringFind each user's longest streak of consecutive active days in SQL (gaps and islands).→SQL & Data EngineeringGiven rows with start and end timestamps, merge all overlapping intervals per user in SQL.→SQL & Data EngineeringTop-N per group in SQL: ROW_NUMBER vs RANK vs DENSE_RANK.→SQL & Data EngineeringWrite SQL for a multi-step funnel: what fraction of users complete each step, in order?→SQL & Data EngineeringSCD Type 2 in Delta Lake: track history with one atomic MERGE.→
COMPANIES THAT ASSUME THIS
