SQL顺序列找出断号
来源:互联网 发布:ipad看漫画软件 编辑:程序博客网 时间:2024/05/17 02:35
select id from info
id
-----------
1
2
3
5
6
7
8
10
11
12
15
(11 行受影响)
方法一:
select (select max(id)+1 from Info where id<a.id) as beginId,(id-1) as endId
from Info a
where
a.id>(select max(id)+1 from Info where id<a.id)
beginId endId
----------- -----------
4 4
9 9
13 14
(3 行受影响)
方法二:
select beginId,(select min(id)-1 from info where id > beginId) as endId
from (
select id+1 as beginId from info where id+1 not in (select id from info) and id < (select max(id) from info)
) as t
beginId endId
----------- -----------
4 4
9 9
13 14
(3 行受影响)
说明:
1、查找结果的两列是断号的区间,如果beginId=endId,则表示缺少该号码,否则表示缺少beginId ~ endId;
2、如果号码1不存在,区间1 ~ select min(id)-1 from info 将无法找出
- SQL顺序列找出断号
- SQL找出顺序列中的断号
- SQL找出不連續的數列
- mysql移动列的顺序sql语句
- 找出SQL Server表名和对应的列名,列类型的语句
- SSIS 执行变量中的脚步输出列顺序与SQL查询列顺序不同
- 找出值最大的行号和列号
- 找出重復記錄SQL
- oracle 找出问题sql
- DataGridView 绑定列顺序
- datagrid 列顺序调整
- 翻转单词顺序列
- 翻转单词顺序列
- 翻转单词顺序列
- 翻转单词顺序列
- 翻转单词顺序列
- 翻转单词顺序列
- 翻转单词顺序列
- Writing custom visualizers for Visual Studio 2005
- JAVA指令集
- progress bar
- TCP/IP通信架构
- linux 下有名管道读写
- SQL顺序列找出断号
- 反射机制补充
- 20.1 滤镜和过渡的基本知识
- Flash 8 支持的HTML标签和用法
- c++ primer 3rd 11.8
- Bitmap与Matrix旋转ImageView
- 1
- autoexp.dat入门
- 5%的神话(关于开发效率与职业方向)