Oracle语法 select min(id)-1 from (select id,rownum from 表名 order by id) where id-rownum=1
第二个问题也可以实现,下面的代码我已测试过了 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
后一中情况:select min(id)-1 from (select id,rownum,id-rownum a from 表名 where id-rownum<>0) group by a
select id+1 from table1 a where not exists(select 1 from table1 b where b.id=a.id+1);
select min(id)-1 from (select id,rownum from 表名 order by id) where id-rownum=1
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
(select id,rownum,id-rownum a from 表名 where id-rownum<>0)
group by a