mysql5中如何查询出自增列的断号(被删掉的)
比如有个自增列c1,现在最大值10万,想要用一条语句查询出所有被删除掉c1的值。
作者: btut2004 发布时间: 2011-05-24
select id-1 from table1 a where not exists (select 1 from table1 where id+1=a.id
作者: ACMAIN_CHM 发布时间: 2011-05-24
得用一个辅助表tb,ID,1-10W.
然后select id from tb where id not in(select id from tb1);
然后select id from tb where id not in(select id from tb1);
作者: zuoxingyu 发布时间: 2011-05-24
狼的不正确
我的数据
tid
1
2
3
5
10
14
15
16
17
18
19
20
21
22
24
用狼给出的语句结果是
tid-1
0
4
9
13
23
我的数据
tid
1
2
3
5
10
14
15
16
17
18
19
20
21
22
24
用狼给出的语句结果是
tid-1
0
4
9
13
23
作者: btut2004 发布时间: 2011-05-24
没考上北大,你的方法,一看就行,就是感觉麻烦点啊。
作者: btut2004 发布时间: 2011-05-24
引用 1 楼 acmain_chm 的回复:
select id-1 from table1 a where not exists (select 1 from table1 where id+1=a.id
select id-1 from table1 a where not exists (select 1 from table1 where id+1=a.id
貌似一句话搞不定,需要些个循环挨个判断
declare count int
set count =1
whiel count<100000 do
if not exists(select 1 from tb where id=count)
insert into temptable
set count=count + 1
end while
select * from temptable
作者: rucypli 发布时间: 2011-05-24