我有这个SQL查询:
SELECT
*,
6371.04 * acos(cos(pi() / 2 - radians(90 - `Tournament`.`latitude`)) * cos(pi() / 2 - radians(90 - 37.226)) * cos(radians(`Tournament`.`longitude`) - radians(-93.4397)) + sin(pi() / 2 - radians(90 - `Tournament`.`latitude`)) * sin(pi() / 2 - radians(90 - 37.226))) AS `Tournament`.`dist`
FROM `tournaments` AS `Tournament`
WHERE 1 = 1
ORDER BY `Tournament`.`dist` ASC
LIMIT 5
我无法弄清楚该声明可能出现的问题。这是我得到的错误:
1064: 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 '.`dist` FROM `tournaments` AS `Tournament` WHERE 1 = 1 ORDER BY `Tournament`' at line 1
有人能指出我正确的方向吗?
答案 0 :(得分:2)
关键字AS
应该后跟一个id,而不是一个复合标识符。
从手册:
可以使用AS alias_name为select_expr指定别名。别名用作表达式的列名,可以在GROUP BY,ORDER BY或HAVING子句中使用。
http://dev.mysql.com/doc/refman/5.0/en/select.html
有关别名的更多信息:http://dev.mysql.com/doc/refman/5.6/en/identifiers.html
答案 1 :(得分:1)
AS `Tournament`.`dist`
这可能是抱怨点。尝试将其分配到dist
。