mysql5中如何查询出自增列的断号(被删掉的)
时间:2011-05-24
来源:互联网
比如有个自增列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
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28