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

哥哥们 求sql
表1ID有1,3,9
我再往表1插入时 ID我想取2
因为
2没有并且 2是没有中的最小的。。。(2<4<5<6....)

速度啊

------解决方案--------------------
探讨
SQL code
with a as(
select 1 as id , 'aa' as name from dual union all
select 2 as id , 'bb' as name from dual union all
select 3 as id , 'bb' as name from dual union all
select 9 as id , 'cc' as ……

------解决方案--------------------
有点错了,修改一下
with a as(
select 1 as id , 'aa' as name from dual union all
select 2 as id , 'bb' as name from dual union all
select 3 as id , 'bb' as name from dual union all
select 5 as id , 'bb' as name from dual union all
select 9 as id , 'cc' as name from dual)
select b.mi
from (select a.id, rownum mi from a order by a.id) b
 where b.id <> b.mi
and rownum = 1
order by b.id