0

我有一个包含信息的数据库:

----------------------------------------------
| HighValue | LowValue | CurrentValue | Code |
----------------------------------------------
|  20       |    6     |      19      | GHI  |
|  10       |    2     |      3       | ABC  |
|  8        |    8     |      8       | JKL  |
|  15       |    8     |      9       | DEF  |
----------------------------------------------

我想找出当前值最接近最低值的代码: 可能按顺序排列,如下所示:

----------------------------------------------
| HighValue | LowValue | CurrentValue | Code |
----------------------------------------------
|  8        |    8     |      8       | JKL  |
|  10       |    2     |      3       | ABC  |
|  15       |    8     |      9       | DEF  |
|  20       |    6     |      19      | GHI  |
----------------------------------------------

如何将一列与另一列进行比较?

4

1 回答 1

1
Select * 
FROM yourtable
ORDER BY ABS(CurrentValue-LowValue) 
于 2012-08-24T22:41:47.197 回答