2

我在我的 MySQL 数据库上使用这一行:

SELECT * FROM `dump` USE INDEX `time_desc` WHERE (`nodeId`=10047 AND `time`<=1377040709 AND `valid`=1) ORDER BY `time` DESC LIMIT 1;

我不知道为什么,但数据库返回以下错误:

[错误:ER_PARSE_ERROR:您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,以在 'time_desc WHERE nodeId=10048 AND time<=1377040709 AND valid=1 ORDER BY 'ti' at line 1 附近使用正确的语法]

关于如何解决这个问题的任何想法?

4

2 回答 2

3

您需要在索引名称周围加上括号

SELECT * 
FROM `dump` USE INDEX (`time_desc`)
WHERE (`nodeId`=10047 AND `time`<=1377040709 AND `valid`=1) 
ORDER BY `time` DESC 
LIMIT 1;
于 2013-10-02T11:04:40.160 回答
0

试试这样: -

SELECT * FROM `dump` USE INDEX (`time_desc`)    --Use paranthesis here
WHERE (`nodeId`=10047 AND `time`<=1377040709 AND `valid`=1) 
ORDER BY `time` DESC 
LIMIT 1;

检查此以供参考

于 2013-10-02T11:05:04.290 回答