0
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 <= CURDATE() LIMIT 10”附近使用正确的语法

4

4 回答 4

2

您将ORDER BYandWHERE子句颠倒了。

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() 
于 2012-05-11T18:22:47.073 回答
1

尝试这个

SELECT id, content, UNIX_TIMESTAMP(timestamp) AS unixtime 
FROM data
WHERE (UNIX_TIMESTAMP(timestamp)) < CURDATE() ORDER BY id ASC  LIMIT 10;
于 2012-05-11T18:42:06.690 回答
1

尝试以下操作:

SELECT id, content, UNIX_TIMESTAMP(timestamp) AS unixtime 
FROM data 
WHERE UNIX_TIMESTAMP(timestamp) <= CURDATE() 
ORDER BY id ASC LIMIT 10;
于 2012-05-11T18:22:38.020 回答
0

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

于 2012-05-11T18:22:41.387 回答