简体   繁体   English

MySQL查询错误1064

[英]Mysql query error 1064

I try to use a query about finding users around with this query: 我尝试使用有关通过此查询查找用户的查询:

                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

but I have this 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,
                    acos(sin(0.761312289853)*sin(radians(lat)) + cos(0.761312289853)*' at line 1

I don't understand the error.. 我不明白错误。

long is a reserved keyword . long保留关键字 If you're going to name a column identifier that you must wrap it in ticks: 如果要命名列标识符,则必须将其包装在刻度中:

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

long is an reserved keyword , you're not allowed to use iut like that because it has another meaning in mysql. long是一个保留关键字 ,不允许使用iut,因为它在mysql中具有另一种含义。

You can use it by using backticks (like the single quotes in php make things litteral): 您可以通过使用反引号来使用它(例如php中的单引号会使内容乱七八糟):

SELECT id, username, lat, `long` FROM table

To make it a bit more obvious, say you have a column in your database called select : 为了使它更加明显,假设您在数据库中有一列名为select的列:

SELECT id,username,select FROM table // this will not work, select is reserved

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM