我收到以下SQL的错误。也许第二组眼睛可以看到问题:
错误:
1064 - 您的SQL语法出错;检查与您的MySQL服务器版本对应的手册,以便在'WHERE generation_id = 21
附近使用正确的语法 在第1行限制0,25'
SQL:
SELECT * FROM data ORDER BY competition ASC, avg_monthly_searches DESC, suggested_bid DESC WHERE generation_id = 21
答案 0 :(得分:3)
问题在于条款的顺序。 From
应该出现在ORDER BY
SELECT * FROM data WHERE generation_id = 21
ORDER BY competition ASC, avg_monthly_searches DESC, suggested_bid DESC
更多信息
下面的是MySQL中SELECT
语句中的子句的顺序。你的可能只是一个错字。但是,这可以帮助某人。
SELECT
[ALL | DISTINCT | DISTINCTROW ]
[HIGH_PRIORITY]
[STRAIGHT_JOIN]
[SQL_SMALL_RESULT] [SQL_BIG_RESULT] [SQL_BUFFER_RESULT]
[SQL_CACHE | SQL_NO_CACHE] [SQL_CALC_FOUND_ROWS]
select_expr [, select_expr ...]
[FROM table_references
[WHERE where_condition]
[GROUP BY {col_name | expr | position}
[ASC | DESC], ... [WITH ROLLUP]]
[HAVING where_condition]
[ORDER BY {col_name | expr | position}
[ASC | DESC], ...]
[LIMIT {[offset,] row_count | row_count OFFSET offset}]
[PROCEDURE procedure_name(argument_list)]
[INTO OUTFILE 'file_name' export_options
| INTO DUMPFILE 'file_name'
| INTO var_name [, var_name]]
[FOR UPDATE | LOCK IN SHARE MODE]]
答案 1 :(得分:2)
导致1064错误
这个错误信息最初可能看起来很神秘。它是指向SQL Query语句中某种语法错误的一般MySQL错误。此错误可能有多种原因。
您需要更改代码,例如:
SELECT * FROM data WHERE generation_id = 21 ORDER BY competition ASC,avg_monthly_searches DESC,suggested_bid DESC
答案 2 :(得分:0)
使用" WHERE"订单条款之前的条款..
所以你的代码转换为
SELECT * FROM data WHERE generation_id = 21 ORDER BY competition ASC, avg_monthly_searches DESC, suggested_bid DESC