我想从表中删除包含超过 7200 秒的列的行。
查询
mysql_query("delete from logged where DATE_ADD ( log, INTERVAL $this->loginDuration SECOND) < NOW()",$this->link);
地点:
name of table = logged;
name of column = log;
$this->loginDuration = 7200;
The value of log in db: 2011-06-25 09:56:51.
Todays date and time [ Now() ] : 2011-07-05 11:39:02
该查询旨在删除日志值为 2011-06-25 09:56:51
的行,因为它早于 7200 秒,但事实并非如此。
我哪里做错了?
最佳答案
DATE_ADD
和括号之间有一个空格:( log, ...
。
使用DATE_ADD(log, ...
来自MySQL docs, Functions and Operators :
Note
By default, there must be no whitespace between a function name and the parenthesis following it. This helps the MySQL parser distinguish between function calls and references to tables or columns that happen to have the same name as a function. However, spaces around function arguments are permitted.
还有:
You can tell the MySQL server to accept spaces after function names by starting it with the
--sql-mode=IGNORE_SPACE
option. (See Section 5.1.6, “Server SQL Modes”.) Individual client programs can request this behavior by using theCLIENT_IGNORE_SPACE
option for mysql_real_connect(). In either case, all function names become reserved words.
关于mysql - mysql 日期查询失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6581410/