我有以下查询来计算地理距离:
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
(带引号),经度等,但似乎没有任何效果。有什么想法吗?
答案 0 :(得分:3)
语法错误的原因是因为您使用反引号将表名和列名包装为一个,导致服务器找到未知列。
`poi.longitude` -- searches for column name [poi.longitude] and not
-- [longitude] from table [poi]
应该是
`poi`.`longitude`
或
poi.longitude
答案 1 :(得分:1)
您没有使用正确的减号, - 。