我有一个这样的数据库:
people
id name zip
1 bill 84058
2 susan 90001
3 john 64354
假设我的输入值是65432
我想要写一个类似这样的查询:
SELECT * FROM people WHERE zip CLOSEST TO 65432 LIMIT 1
并在行返回时获取john
。
我在Postgresql中找不到最接近命令的是什么
发布于 2019-07-24 03:30:49
您可以使用ABS
函数:
SELECT *
FROM people
ORDER BY ABS(65432 - zip) ASC LIMIT 1
https://stackoverflow.com/questions/57170958
复制相似问题