SQL:选择尚不存在的最低值

编程入门 行业动态 更新时间:2024-10-23 21:24:20
本文介绍了SQL:选择尚不存在的最低值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

在 TableA 中,我有一个 int 列.

In TableA I have an int column.

是否可以仅使用 select 语句来选择列中不存在且大于 0 的最小值?

Is it possible using only a select statement to select the minimum value in the column that DOES NOT EXIST and is greater then 0?

例如,如果 col 的值为 1,2,9,则 select 语句将返回 3.如果 col 有 9,10,11,它将返回 1.

For example, if the col has the values 1,2,9 the select statement will return 3. If the col has 9,10,11 it will return 1.

我可以使用临时表或使用循环来实现这一点,但我想知道是否可以仅使用 select 语句来实现?

I can achieve this using a temp table or using a loop, but I'm wondering if I can do it using just a select statement?

推荐答案

select min(nt.id) from numbertable nt left outer join originaldata od on nt.id=od.id where od.id is null

有一个从 1 到最大值(或更高)的数字表

have a number table that goes from 1 to your max value (or higher)

更多推荐

SQL:选择尚不存在的最低值

本文发布于:2023-11-22 20:07:29,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1618829.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:尚不   低值   SQL

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!