Skip to content
Advertisement

Making groups of dates in SQL Server

I have a table contains ids and dates, I want to groups of dates for each id

I want to check where are gaps in date for each id to get output like

Advertisement

Answer

This is a form of gaps-and-islands problem. The simplest solution is to generate a sequential number for each id and subtract that from the date. This is constant for dates that are sequential.

So:

Here is a db<>fiddle.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement