我尝试使用查询来查找此查询的用户:
Select id, username, lat, long,
acos(sin(0.761312289853)*sin(radians(lat)) + cos(0.761312289853)*cos(radians(lat))*cos(radians(long)-0.0676354285243)) * 6371 As D
From (
Select id, username, lat, long,
From rcp_users
Where lat Between 43.4491099949 And 43.7908522051
And long Between 3.63919239657 And 4.11125680343
) As FirstCut
Where acos(sin(0.761312289853)*sin(radians(lat)) + cos(0.761312289853)*cos(radians(lat))*cos(radians(long)-0.0676354285243)) * 6371 < 30
Order by D
但我有这个错误:
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,
acos(sin(0.761312289853)*sin(radians(lat)) + cos(0.761312289853)*' at line 1
我不明白错误..
答案 0 :(得分:5)
long
是reserved keyword。如果您要命名列必须将其包装在列表中的列标识符:
Select id, username, lat, `long`,
acos(sin(0.761312289853)*sin(radians(lat)) + cos(0.761312289853)*cos(radians(lat))*cos(radians(`long`)-0.0676354285243)) * 6371 As D
From (
Select id, username, lat, `long`,
From rcp_users
Where lat Between 43.4491099949 And 43.7908522051
And `long` Between 3.63919239657 And 4.11125680343
) As FirstCut
Where acos(sin(0.761312289853)*sin(radians(lat)) + cos(0.761312289853)*cos(radians(lat))*cos(radians(`long`)-0.0676354285243)) * 6371 < 19
Order by D
答案 1 :(得分:0)
long
是一个reserved keyword,你不允许像这样使用iut,因为它在mysql中有另外的含义。
你可以通过使用反引号来使用它(就像php中的单引号一样):
SELECT id, username, lat, `long` FROM table
为了使它更明显,假设您的数据库中有一个名为select
的列:
SELECT id,username,select FROM table // this will not work, select is reserved