如何查漏编号字段

 

select * from TTT

 

select
t1.id + 1 as 'start missing id',
MIN(t2.id) - 1 as 'end missing id',
MIN(t2.id) - t1.id - 1 as 'count of missing id'
from
TTT t1 left join TTT t2
on t1.id < t2.id
group by t1.id
having MIN(t2.id) - t1.id > 1

你可能感兴趣的:(如何查漏编号字段)