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'附近
答案 0 :(得分:2)
您的ORDER BY
和WHERE
条款已被撤消。
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语句。