我正在尝试从数据库获取坐标和位置,但是我的服务器返回此错误:
Error: You have an error in your SQL syntax; check the manual that corresponds to your
MySQL server version for the right syntax to use near
'long ) - radians(0) ) + sin( radians(0) ) * sin( radians( lat ) ) ) ) AS distanc'
at line 1
Query:
SELECT id,
address,
name,
(3959 * acos(cos(radians(0)) *
cos(radians(lat)) *
cos(radians(long) - radians(0)) +
sin(radians(0)) *
sin(radians(lat)))
) AS distance
FROM places
HAVING distance < 10
ORDER BY distance
LIMIT 0, 20;
我是否必须使用`来转义“ lat”和“ long”,还是该公式完全错误?谢谢。
另外,我使用的坐标是0、0(仅用于测试目的)。
最佳答案
LONG是mysql中的保留字。将其用作列名时,请使用反引号将其转义。
关于mysql - MySQL查询返回错误,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/6442902/