samedi 16 juillet 2016

SQL - Select first n row where next n Row values are sequential + 1

I have a table with row ID and Cct numbers. The Cct column can be +1 sequential depending on the preceeding select statement.

I want to find the first row where the next n rows cct no. increments + 1 to n-1.

Sample

ID    Cct
1      1
2      3
7      5
8      6
10     9
11     10
12     11

if n = 2 I want to select row with ID 7 because it is the first time that the next n rows cct value are value + 1

if n = 3 I want to select row with ID 10 as the next n-1 rows are incremented by + 1

Hope this is clear

Aucun commentaire:

Enregistrer un commentaire