我在表格“A”中有一个GPS坐标Lat 4.649182 Long -74.108948,我需要用表格“B”中存储的值来计算距离:
Id UserID Lat Long
1 1 4.649200 -74.109200
2 1 4.649110 -74.108860
3 2 4.648985 -74.108831
4 3 4.64923 -74.10893666
通常使用此公式计算两点之间的距离:
SELECT (acos(sin(radians(LATITUDE_1)) * sin(radians(LATITUDE_2)) +
cos(radians(LATITUDE_1)) * cos(radians(LATITUDE_2)) *
cos(radians(LONGITUDE_1) - radians(LONGITUDE_2))) * 6378) as Distance;
但是我需要结果显示UserID = 1时各个点之间的距离,它看起来像这样
Id UserID Lat Long Distance
1 1 4.649200 -74.109200 XX
2 1 4.649110 -74.108860 XX