Island Aggregates: Length, Start, End
Concepts covered: sqlLagLead
The other common variant is conditional islands. The runs are not defined by adjacency at all; they are defined by a status or attribute being constant for a stretch of rows. 'Find contiguous periods where a subscription was active.' 'Find stretches where a server was healthy.' 'Find runs of days the stock closed above its 50-day moving average.' These are gaps and islands where 'consecutive' means 'sharing the same value' rather than 'adjacent in the sequence.' The LAG form handles this case cleanly with one change to the boundary CASE. The status-change variant What changed in the boundary CASE The boundary condition is no longer about a time gap; it is about a value change. is_new_run is 1 when the predecessor's status is different from the current row's status (or when there is no pred
About This Interactive Section
This section is part of the Gaps and Islands: Intermediate lesson on DataDriven, a free data engineering interview prep platform. Each section includes explanations, worked examples, and hands-on code challenges that execute in real time. SQL queries run against a live database. Python runs in a sandboxed Docker container. Data modeling problems validate against interactive schema canvases. All content is framed around what data engineering interviewers actually test at companies like Meta, Google, Amazon, Netflix, Stripe, and Databricks.
How DataDriven Lessons Work
DataDriven combines four interview rounds (SQL, Python, Data Modeling, Pipeline Architecture) with adaptive difficulty and spaced repetition. Easy problems get harder as you improve. Weak concepts resurface until you master them. Your readiness score tracks progress across every topic interviewers test. Every lesson section ends with problems you solve by writing and running real code, not by picking multiple-choice answers.