Skip to content
Advertisement

Sql query to Count Total Consecutive Years from latest year

I have a table Temp:

I want to calculate the total consecutive years starting from the most recent Year. Result should look like this:

Advertisement

Answer

e.g. for ID=1:

As long as there’s no gap, both sequences increase the same.

Now check for equal sequences and count the rows:

Edit:

Based on your year zero comment:

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