当前位置: 代码迷 >> 其他数据库 >> SQLite3 中怎么查找最小可用的空缺ID
  详细解决方案

SQLite3 中怎么查找最小可用的空缺ID

热度:8779   发布时间:2013-02-26 00:00:00.0
SQLite3 中如何查找最小可用的空缺ID?
最近在学习SQLite3,遇到一个棘手的问题。
想在表student(id,name,age)中查找到空缺的id号,可用什么命令解决吗?
比如这样:
1 | Yang | 20
2 | Wang| 23
4 | Liu | 19
5 | Li | 25
7 | Zhou | 34
8 | Feng | 28
想找到最小可用的id号3,怎样做呢?
先谢谢大侠们咯.......

------解决方案--------------------------------------------------------


SELECT Min(id)+1 
FROM t2 AS a
WHERE not Exists (select 1 from t2 where id=a.id+1)

------解决方案--------------------------------------------------------
SQL code
select min(id+1)from student swhere not exists (select id from student where id=a.id+1