我有一张桌子
+------------+------------+--------------+---------------+
| 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磅
这可能吗?
答案 0 :(得分:-1)
很简单:
SELECT * FROM table WHERE state = '$state' AND lbs >= '$lbs' LIMIT 1