gpt4 book ai didi

sql - Postgres 地理定位点距离

转载 作者:行者123 更新时间:2023-11-29 11:27:22 24 4
gpt4 key购买 nike

我正在尝试进行查询以确定 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

但它给我这个错误

ERROR: column "distance" does not exist LINE 5: HAVING distance < 25

如果我删除“HAVING distance < 25”部分,查询运行正常

最佳答案

好的,我解决它检查其他问题

SELECT t.* FROM (
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) t
WHERE distance < 1
ORDER BY distance

关于sql - Postgres 地理定位点距离,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20041488/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com