最近在学习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