我们可以使用 where 子句运行 mysql 查询,如下所示
TIME_TO_SEC(TIMEDIFF('2012-08-22 06:25:12',lastEventTime)) >70
我们现在需要检查的是尝试输入 =null 但没有显示的 null 值?需要什么?
示例查询如下,谢谢,它有效。我的下一个问题现在必须对 lastEvenTime 列建立索引吗?
SELECT
tblTimeLog.timeLogID,
TIME_TO_SEC(TIMEDIFF('2012-08-22 06:25:12',lastEventTime)) As timeDifference
FROM tblTimeLog
WHERE tblTimeLog.timeID = 2209
And (TIME_TO_SEC(TIMEDIFF('2012-08-22 06:25:12',lastEventTime)) IS NULL
OR TIME_TO_SEC(TIMEDIFF('2012-08-22 06:25:12',lastEventTime)) > 100)
最佳答案
你可以替换这个
And (TIME_TO_SEC(TIMEDIFF('2012-08-22 06:25:12',lastEventTime)) IS NULL
OR TIME_TO_SEC(TIMEDIFF('2012-08-22 06:25:12',lastEventTime)) > 100)
与
and (lastEventTime IS NULL
OR TIME_TO_SEC(TIMEDIFF('2012-08-22 06:25:12',lastEventTime)) > 100)
或将coalesce
与适当选择的默认值一起使用(在NULL
的情况下):
and TIME_TO_SEC(TIMEDIFF('2012-08-22 06:25:12',
coalesce(lastEventTime, '1900-01-01')) > 100
尽管合并位仅与 WHERE
子句相关;对于 SELECT
部分,如果 lastEventTime 为 NULL
,您将得到 NULL
。
关于mysql - 如何检查 TIME_TO_SEC(TIMEDIFF 值的 where 子句中是否为 null?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12071346/