Detect sessions and gaps using SQL LEAD | Apple