我有一个纬度\经度点的数据库。我试图获得按距离排序的 DISTINCT 舍入结果。我的查询如下:
SELECT
DISTINCT ROUND(`lat`,2), ROUND(`lon`,2),
( 3959 * acos( cos( radians(LAT_HERE) )
* cos( radians( `lat` ) )
* cos( radians( `lon` ) - radians(LONG_HERE) )
+ sin( radians(LAT_HERE) )
* sin( radians( `lat` ) ) ) ) AS distance
FROM `user_data`
HAVING distance <= 99
ORDER BY distance
LIMIT 100
独特的是在回合前运行。例如 (29.333,29.334), (29.331,29.332) 将显示两次。