如何将此 mysql 查询转换为 postgres 9.4

How can I convert this mysql query into postgres 9.4

首先,我在两个数据库(MySQL 和 Postgres)中有相同的 table 名称、列和数据,我用于 MySQL 5.6.24 的查询可以正常工作这个

select *,abs(longitudes - -81.4563009)+abs(latitudes-28.11657) as LowestNum 
from zips group by LowestNum limit 1

当我将相同的查询放入 postgres 9.4 时,我基本上是在尝试获取给定经纬度的最近位置,但我收到一条错误消息,指出

ERROR: column "zips.zip" must appear in the GROUP BY clause or be used in an aggregate function
SQL state: 42803
Character: 8

然后我改变周围的事情并这样做

select *, abs(longitudes - -81.3952524)+abs(latitudes-28.4583868) as   
LowestNum from zips group by LowestNum,zips.zip limit 1

我收到这个错误

ERROR: column "zips.ziptype" must appear in the GROUP BY clause or be used in an aggregate function
SQL state: 42803
Character: 8

我是 postgres 的新手,但一直在查看文档并四处搜索,但没有任何建议。

这个怎么样:

select *, abs(longitudes - -81.4563009)+abs(latitudes-28.11657) as LowestNum 
from zips 
order by LowestNum ascending 
limit 1

抱歉,我没有 PostgreSQL 实例来测试它。

order by [..] ascending/descending limit 1 是避免 minmax 的常见方法,以及当您有多个结果列(group by、连接)时它们带来的困难.