我正在使用以下查询:
SELECT message,timestamp
FROM botlogs.tbllogs
WHERE message like '%Failed to grab car amount
or 0 website%' and timestamp > Subtime('2011-08-01 13:20','0:60')
虽然我有 8/1/2011 1:21:53pm 的行,但上述查询不返回任何行。这是为什么?
如果我运行
select timestamp,message
from botlogs.tbllogs
where message like Failed to grab car amount
or 0 website%' and timestamp < '2011-08-01 13:20' - INTERVAL 180 SECOND
它返回 7/31/2011 9:27:24
pm 的错误。
最佳答案
因为:
mysql> SELECT Subtime('2011-08-01 13:20','0:60');
+------------------------------------+
| Subtime('2011-08-01 13:20','0:60') |
+------------------------------------+
| NULL |
+------------------------------------+
1 row in set, 1 warning (0.04 sec)
试试这个
mysql> SELECT Subtime('2011-08-01 13:20','00:01:00');
+----------------------------------------+
| Subtime('2011-08-01 13:20','00:01:00') |
+----------------------------------------+
| 2011-08-01 13:19:00 |
+----------------------------------------+
1 row in set (0.00 sec)
或者
mysql> SELECT '2011-08-01 13:20' - INTERVAL 60 SECOND;
+-----------------------------------------+
| '2011-08-01 13:20' - INTERVAL 60 SECOND |
+-----------------------------------------+
| 2011-08-01 13:19:00 |
+-----------------------------------------+
1 row in set (0.01 sec)
关于mysql - 使用 subtime() 的查询意外地没有返回任何行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6903364/