想象一下,有一个表,如下一个:查找自动递增值差距
create table test (
id int auto_increment,
some int,
columns int
)
,然后得到使用这个表了很多。行被插入并且行被删除,并且随着时间的推移,可能会有数字中的差距一度被自动递增。举个例子,如果我在某些时候做下面的查询:
select top 10 id from test
我可能会像
3
4
6
7
9
10
13
14
18
19
如何设计出返回遗漏值1,2,5查询, 8等?
看看这篇文章:https://www.simple-talk.com/sql/t-sql-programming/the-sql-of-gaps-and-islands-in-sequences/ – Milen 2014-10-27 11:39:48
什么版本您正在使用SQL Server? – 2014-10-27 11:40:31