sql - How to find gaps in sequential numbering in mysql? -
we have database table values imported system. there auto-increment column, , there no duplicate values, there missing values. example, running query:
select count(id) arrc_vouchers id between 1 , 100 should return 100, returns 87 instead. there query can run return values of missing numbers? example, records may exist id 1-70 , 83-100, there no records id's of 71-82. want return 71, 72, 73, etc.
is possible?
here's version works on table of size (not on 100 rows):
select (t1.id + 1) gap_starts_at, (select min(t3.id) -1 arrc_vouchers t3 t3.id > t1.id) gap_ends_at arrc_vouchers t1 not exists (select t2.id arrc_vouchers t2 t2.id = t1.id + 1) having gap_ends_at not null gap_starts_at- first id in current gapgap_ends_at- last id in current gap
Comments
Post a Comment