日期:2014-05-17  浏览次数:20916 次

sql语句的请教?(查找连续数据中的一个空缺数据)
怎样用一条sql查找连续数据中的一个空缺数据,如:这样一个数列1,2,3,4,5,6,7,9,10,11....... 
用一个语句把空缺的8找出来?

------解决方案--------------------
测试数据:
SQL code

CREATE TABLE T185
(
    F1 NUMBER(2)
);

INSERT INTO T185 VALUES(1);
INSERT INTO T185 VALUES(2);
INSERT INTO T185 VALUES(3);
INSERT INTO T185 VALUES(4);
INSERT INTO T185 VALUES(5);
INSERT INTO T185 VALUES(6);
INSERT INTO T185 VALUES(7);
INSERT INTO T185 VALUES(9);
INSERT INTO T185 VALUES(10);
INSERT INTO T185 VALUES(11);

------解决方案--------------------
SQL code

select id-1 from test a 
where id not in(select 1+id from test 
where id not in(select max(id) from test)) and id not in (select min(id) from test)

------解决方案--------------------
SQL code

select id-1 from test a 
where id not in(select 1+id from test) and id not in (select min(id) from test)