我正在尝试在Postgres数据库中进行查询,以确定地理位置点之间的距离。以下是我的查询:
SELECT latitude, longitude, SQRT(
POW(69.1 * (latitude - 31.8679), 2) +
POW(69.1 * (-116.6567 - longitude) * COS(latitude / 57.3), 2)) AS distance
FROM locations
HAVING distance < 25
ORDER BY distance
但是它给了我这个错误
错误:列“distance”不存在 第5行:HAVING distance < 25
如果我删除“HAVING distance < 25”部分,查询就可以正常运行。