Interview › Gaps and islands

SQL interview: consecutive days / islands

An island is a run of days with no gap. Subtract a row number from the date and the run shares a key.

Prompt. For each customer, find streaks of consecutive order dates and the length of each streak.

Hint: DATEADD(day, −rn, day) as grp

Two orders on one day are one day. Group the date first.

Then write it on a ticket

Monday is free. A colleague asks, you type, we mark it.

Clock in free