Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/78.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 查找达到的最高阈值_Sql_Sql Server - Fatal编程技术网

Sql 查找达到的最高阈值

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 INT,Reach BIT,表格如下所示:

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;
另一种方法是查看下一个值: