-2

我有以下查询来计算地理距离:

SELECT (
   (ACOS(SIN(39 * PI() / 180) * 
         SIN(`latitude` * PI() / 180) +
         COS(39 * PI() / 180) *
         COS(`latitude` * PI() / 180) *
         COS((32–`poi.longitude`) * PI()/180)
        ) * 180 / PI()
   ) * 60 * 1.1515
       ) AS distance
FROM     `poi`
HAVING   distance <= 10
ORDER BY distance ASC

当我运行查询时出现错误:

语法错误或访问冲突:1064 您的 SQL 语法有错误;查看与您的 MySQL 服务器版本相对应的手册,了解在 '– poi.longitude) * PI()/180...附近使用的正确语法

因此,如果我将 (32–<code>poi.longitude) 替换为 (3) 之类的数字,那么它可以工作,但即使我使用 (32–21) 作为数学运算,它也会引发错误。我poi.longitudelongitude(带引号)、经度等替换,但似乎没有任何效果。有任何想法吗?

4

2 回答 2

3

语法错误的原因是因为您将表名和列名用反引号括起来,导致服务器查找未知列。

`poi.longitude` -- searches for column name [poi.longitude] and not
                -- [longitude] from table [poi]

它应该是

`poi`.`longitude`

或者

poi.longitude
于 2013-03-28T13:06:56.757 回答
1

您没有使用正确的减号 -。

于 2013-03-28T13:44:41.990 回答