1

使用以下选择,我试图在 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
4

1 回答 1

0

您在给您带来麻烦的部分之前的最后一个搜索词缺少结束“'”。除非这只是这里的错字。如果不是这样,请告诉我,我再看看

编辑:

SELECT *, (distance_between 52.5960 , -1.9110 , 
GOFL_LOCCGRP_TPEGILOC_TO_POINTCOORDINATES_LATITUDE , GOFL_LOCCGRP_TPEGILOC_TO_POINTCOORDINATES_LONGITUDE) AS DISTANCEFROMEVENT 
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'

好的,所以您需要调用 SELECT 中的 DISTANCEFROMEVENT 字段以使其出现。

于 2012-05-06T12:46:48.870 回答