SQL - 从具有数字间隙的记录集中获取行中的下一个数字
我有一个 SQL 记录,其中的数字全部乱序(有间隙),例如:1,2,3,7,9,11..... 我只想得到第一个缺失的号码。
我尝试过类似的方法,但我只是不知道 SQL 能否使其正常工作。
strQuery = "SELECT N as NextNum FROM LOADS WHERE N > 0 AND N <= (SELECT MAX(LOAD_NO) FROM @LOADS) AND N NOT IN (SELECT LOAD_NO FROM @LOADS)"
objNextNum.Open strQuery
lastLoadNo= objNextNum("NextNum")
response.write "NEXT LOAD NUMBER IS: " & lastLoadNo
我在微软网站上找到了这个例子,但我无法让它工作。
感谢您的帮助!
I have a SQL Record that has number that are all out of order (has gaps) for example: 1,2,3,7,9,11.....
I would like to get only the first missing number.
I tried something like this but I just don't know SQL to make it work correctly.
strQuery = "SELECT N as NextNum FROM LOADS WHERE N > 0 AND N <= (SELECT MAX(LOAD_NO) FROM @LOADS) AND N NOT IN (SELECT LOAD_NO FROM @LOADS)"
objNextNum.Open strQuery
lastLoadNo= objNextNum("NextNum")
response.write "NEXT LOAD NUMBER IS: " & lastLoadNo
I found that example on a ms website but I cannot get it to work.
Thanks for any help!!!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在某处看到这个,但不记得在哪里,或者我会给出正确的归属,但你应该能够使用这个:
saw this somewhere, can't remember where though, or i'd give proper attribution, but you should be able to use this: