从不存在的列中选择最小数 [英] Select minimum number from column which not exist
本文介绍了从不存在的列中选择最小数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
I have in my column (id) values
4
5
10
我想选择不存在的最小数量.示例值 1 然后 2 然后 3 然后 6 .....
I want to choose minimum nubmer which not exists. Example value 1 then 2 then 3 and then 6.....
我正在尝试此代码
IF not EXISTS(SELECT min(id) from table1) select...
推荐答案
你可以找到第一行不存在 Id + 1 的行.
You can find the first row where there does not exist a row with Id + 1.
试试这个.
SELECT TOP 1 t1.Id+1 as ID
FROM table t1
WHERE NOT EXISTS(SELECT * FROM table t2 WHERE t2.Id = t1.Id + 1)
ORDER BY t1.Id;
检查这个..在线演示在这里
这篇关于从不存在的列中选择最小数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文