← 🗄️ 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
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 EngineeringFind the top-N records per group and a running total per group in SQL.→SQL & Data EngineeringWrite SQL for a multi-step funnel: what fraction of users complete each step, in order?→SQL & Data EngineeringImplement Slowly Changing Dimension Type 2 history tracking in a Delta lakehouse.→
COMPANIES THAT ASSUME THIS
