select a.id,max(b.id)
from table as a,table as b
where a.id>b.id
group by a.id
having a.id - max(b.id)>1

解决方案 »

  1.   

    Oracle语法
    select min(id)-1 from (select id,rownum from 表名 order by id) where id-rownum=1
      

  2.   

    第二个问题也可以实现,下面的代码我已测试过了
    ID STR
    -- -------
     1 hehe
     2 hehe
     3 hehe
     5 hehe
     6 hehe
     8 heheselect id from 
    (select min(id)-1 id,min(younum),mynum from 
      (select id,rownum younum,id-rownum mynum from caishui.tests order by id) group by mynum)
    where id>0得到
           ID
    ---------
            4
            7
      

  3.   

    后一中情况:select min(id)-1 from 
    (select id,rownum,id-rownum a from 表名 where id-rownum<>0)
    group by a
      

  4.   

    select id+1 from table1 a where not exists(select 1 from table1 b where b.id=a.id+1);
      

  5.   

    铁鹰兄和fighters的rownum运用可谓纯熟,因为我的据库没有rownum所以我的做法和过客兄的做法类似,使用的是自连接的变种。但过客兄的边界(最大数)有点小问题。大家都有些独到的方法,但我觉得我的第二个问题还需要讨论。比如连续缺少n条数据。可能大家只能找到最小的数据。我提醒大家一下,缺少的数据可能比存在的数据还要多,如果通过建立“存在数据的子集”与“缺少的数据集合”建立一一映射来找出缺少的数据,必然要有所遗漏,这是一直困扰我的难题。