MySQL查询搜索最接近的最高编号

时间:2015-07-22 08:41:54

标签: php mysql

我有一张桌子

+------------+------------+--------------+---------------+
|    lbs     |     tx     |      ca      |       ny      |
+------------+------------+--------------+---------------+
|     1      |     20     |      30      |       40      |
+------------+------------+--------------+---------------+
|     2      |     25     |      35      |       45      |
+------------+------------+--------------+---------------+
|     3      |     30     |      40      |       50      |
+------------+------------+--------------+---------------+

我希望MySQL查询根据两个变量获得最接近的最高编号。像

这样的东西
SELECT * FROM table WHERE state = '$state' AND lbs = '$lbs' NEAREST HIGHEST

在1.3磅的输入中选择2磅

这可能吗?

1 个答案:

答案 0 :(得分:-1)

很简单:

SELECT * FROM table WHERE state = '$state' AND lbs >= '$lbs' LIMIT 1