使用以下选择,我试图在 PHP 循环遍历每一行时查看每一行,拉出当前位置半径并使用 PROC 计算出每个“事件”到当前位置的距离,然后在移动到下一行之前distance_between
填充。DISTANCEFROMEVENT
我跌倒的地方(因为大部分工作)是添加动作
distance_between 52.5960 , -1.9110 ,
GOFL_LOCCGRP_TPEGILOC_TO_POINTCOORDINATES_LATITUDE ,
GOFL_LOCCGRP_TPEGILOC_TO_POINTCOORDINATES_LONGITUDE AS DISTANCEFROMEVENT
我不清楚如何将其加入SELECT
语句的语法,尽管我自己知道它应该可以工作。
SELECT * FROM Current
WHERE (GOFL_LOCCGRP_TPEGILOC_TO_POINTCOORDINATES_LATITUDE <53.319589001447
AND
GOFL_LOCCGRP_TPEGILOC_TO_POINTCOORDINATES_LATITUDE > 51.872410998553
AND
GOFL_LOCCGRP_TPEGILOC_TO_POINTCOORDINATES_LONGITUDE > -2.6349916029658
AND
GOFL_LOCCGRP_TPEGILOC_TO_POINTCOORDINATES_LONGITUDE < -1.1870083970342
AND
VALIDPERIOD_STARTOFPERIOD < '12-05-06 16:15:31'
AND
VALIDPERIOD_ENDOFPERIOD > '12-05-06 16:15:31' ,
distance_between 52.5960 , -1.9110 , GOFL_LOCCGRP_TPEGILOC_TO_POINTCOORDINATES_LATITUDE , GOFL_LOCCGRP_TPEGILOC_TO_POINTCOORDINATES_LONGITUDE AS DISTANCEFROMEVENT )
我能得到的任何指导将不胜感激。
人族
CREATE FUNCTION distance_between (from_lat DECIMAL(6, 3),
from_lng DECIMAL(6, 3),
to_lat DECIMAL(6, 3),
to_lng DECIMAL(6, 3))
RETURNS DECIMAL(11, 3)
RETURN 6371 * 2 * ATAN2(SQRT(POW(SIN(RADIANS(to_lat - from_lat)/2), 2) +
POW(SIN(RADIANS(to_lng - from_lng)/2), 2) * COS(RADIANS(from_lat)) *
COS(RADIANS(to_lat))), SQRT(1 - POW(SIN(RADIANS(to_lat - from_lat)/2), 2) +
POW(SIN(RADIANS(to_lng - from_lng)/2), 2) * COS(RADIANS(from_lat)) * COS(RADIANS(to_lat))));
在职的.............
SELECT *, ( 3959 * acos( cos( radians(52.5960) ) * cos( radians( GOFL_LOCCGRP_TPEGILOC_TO_POINTCOORDINATES_LATITUDE ) ) * cos( radians( GOFL_LOCCGRP_TPEGILOC_TO_POINTCOORDINATES_LONGITUDE ) - radians(-1.9110) ) + sin( radians(52.5960) ) * sin( radians( GOFL_LOCCGRP_TPEGILOC_TO_POINTCOORDINATES_LATITUDE ) ) ) ) AS DISTANCEFROMEVENT FROM Current HAVING DISTANCEFROMEVENT < 50 ORDER BY DISTANCEFROMEVENT