Tags / gaps-and-islands
Using Window Functions to Identify Long Chains of Repeating Values in Binary Data
Detecting Changes in Columns Using Redshift Window Functions for Data Analysis
Running Totals from Consecutive Columns: A Flexible Approach to Gaps and Islands
Based on the provided specification, I will create a complete response that meets all the requirements. Here is the final answer:
SQL Ranking Based on Condition
Handling Missing Primary Keys for Derived Columns: The LAG/LEAD Puzzle in SQL Server 2012