Sql 查找达到的最高阈值
我有一个表,其中包含两列,存储可以达到的某些阈值的值。 表格列为:ThresholdValue INT,Reach BIT,表格如下所示:Sql 查找达到的最高阈值,sql,sql-server,Sql,Sql Server,我有一个表,其中包含两列,存储可以达到的某些阈值的值。 表格列为:ThresholdValue INT,Reach BIT,表格如下所示: ThresholdValue | Reached ------------------------ 10000 | 0 20000 | 0 30000 | 0 45000 | 0 50000 | 0 我需要根据达到的阈值更新达到的列。 例如,当达到的值为25000时
ThresholdValue | Reached
------------------------
10000 | 0
20000 | 0
30000 | 0
45000 | 0
50000 | 0
我需要根据达到的阈值更新达到的列。
例如,当达到的值为25000时,我希望第二行设置为1,这样看起来像这样
ThresholdValue | Reached
------------------------
10000 | 0
20000 | 1
30000 | 0
45000 | 0
50000 | 0
解决这个问题最简单的方法是什么?
非常感谢您提供的任何提示您可以使用子查询来标识行:
update t
set reached = 1
from (select top (1) t.*
from t
where t.ThresholdValue <= 25000
order by ThresholdValue desc
) t;
另一种方法是查看下一个值:
您可以使用子查询来标识行:
update t
set reached = 1
from (select top (1) t.*
from t
where t.ThresholdValue <= 25000
order by ThresholdValue desc
) t;
另一种方法是查看下一个值: