Find missing data in consecutive numbers

Viewed 33

Table has an index , it starts from 1 and the rest will be sequentially numbered, and now there are missing data that cause discoontinuity, how can I write sql to find the serial number missing, such as the following, by serial number sorting line number is greater than the ratio of the current line number 1 data.

1 Answers

You can use the deltas function, for example:

t=table(1..10 join [12, 14,16] as id)  
select id from t where deltas(id)>1

The id in the above t table jumps from 10 to 12, 14, 16, and the select statement can query 12, 14, and 16.

Related