Mysql不识别数学运算

时间:2013-03-28 13:05:27

标签: mysql sql select

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

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 ...

附近使用正确的语法

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

2 个答案:

答案 0 :(得分:3)

语法错误的原因是因为您使用反引号将表名和列名包装为一个,导致服务器找到未知列。

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

应该是

`poi`.`longitude`

poi.longitude

答案 1 :(得分:1)

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