mysql - 使用 subtime() 的查询意外地没有返回任何行

标签 mysql datetime time

我正在使用以下查询:

 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/

相关文章:

mysql - 将值从一行复制到下一行

java - 在 Hibernate 中保留 Joda 日期时间

python - 根据 Python/Pandas 中不稳定的月度数据度量估算每日值

php - 如何将 PDT 时间格式转换为这种格式 `2016-09-13 08:56:55 +0000` - 使用 PHP?

ios - 如何在午夜不触发 applicationSignificantTimeChange

python - 如何在 python 中找到格式中两个时间之间的差异?

php - fetch() 在 while 循环内不起作用

php - 保存 'model attributes' 不起作用(需要帮助)

C++ 添加 1 年至今

java - 为什么这个 while 循环不能每秒打印 1,000 次?