SELECT *
FROM offer
ORDER BY profile.location <-> "offer.profile.location"
我有2个表:一个是offer
,另一个是profile
。用户在个人资料中提供了offer
,因此profile
中的用户如何使用postgis postgresql查询查找最近的offer
?
答案 0 :(得分:2)
SELECT offer.* FROM offer, profile
WHERE ST_DWithin(offer.location, profile.location, 5000)
ORDER BY ST_Distance(offer.location, profile.location);