postgis查询查找邻居

2024-03-28 16:54:21 发布

您现在位置:Python中文网/ 问答频道 /正文

SELECT * 
FROM offer 
ORDER BY profile.location <-> "offer.profile.location"

我有两个表:一个是offer,另一个是profileoffer由用户在配置文件中提供,那么对于profile中的用户,如何使用postgis postgresql查询以查找最近的offer?你知道吗


Tags: 用户frombypostgresql配置文件orderlocationprofile
1条回答
网友
1楼 · 发布于 2024-03-28 16:54:21

像这样的东西。在这种情况下,假设SRID为4326,位置之间的距离必须在5000米以内,报价结果按距离排序。你知道吗

 SELECT offer.* FROM offer, profile
    WHERE ST_DWithin(offer.location, profile.location, 5000)
    ORDER BY ST_Distance(offer.location, profile.location);

相关问题 更多 >