这条SQL语句出了什么问题 - 语法错误#1064?

时间:2012-05-11 18:20:34

标签: sql syntax phpmyadmin syntax-error

SELECT id, content, UNIX_TIMESTAMP(timestamp) AS unixtime 
FROM data
ORDER BY id ASC 
WHERE unixtime <= CURDATE() LIMIT 10;

SELECT id, content, UNIX_TIMESTAMP(timestamp) AS unixtime 
FROM data
ORDER BY id ASC 
WHERE unixtime < CURDATE() LIMIT 10;

所有phpAdmin告诉我的是:

  

#1064 - 您的SQL语法出错;检查与MySQL服务器版本对应的手册,以获得正确的语法   在第1行'WHERE unixtime&lt; = CURDATE()LIMIT 10'附近

4 个答案:

答案 0 :(得分:2)

您的ORDER BYWHERE条款已被撤消。

SELECT id, content, UNIX_TIMESTAMP(timestamp) AS unixtime 
FROM data
WHERE unixtime < CURDATE()
ORDER BY id ASC LIMIT 10;

SELECT id, content, UNIX_TIMESTAMP(timestamp) AS unixtime 
FROM data
WHERE unixtime <= CURDATE() 
ORDER BY id ASC LIMIT 10;

我刚刚意识到您的问题的一部分,因为您在WHERE子句中引用了别名。:

WHERE UNIX_TIMESTAMP(timestamp) <= CURDATE() 

WHERE UNIX_TIMESTAMP(timestamp) < CURDATE() 

答案 1 :(得分:1)

尝试以下方法:

SELECT id, content, UNIX_TIMESTAMP(timestamp) AS unixtime 
FROM data 
WHERE UNIX_TIMESTAMP(timestamp) <= CURDATE() 
ORDER BY id ASC LIMIT 10;

答案 2 :(得分:1)

试试这个

SELECT id, content, UNIX_TIMESTAMP(timestamp) AS unixtime 
FROM data
WHERE (UNIX_TIMESTAMP(timestamp)) < CURDATE() ORDER BY id ASC  LIMIT 10;

答案 3 :(得分:0)

您需要在order by语句之前使用where语句。