0

我们可以像这样运行带有 where 子句的 mysql 查询

TIME_TO_SEC(TIMEDIFF('2012-08-22 06:25:12',lastEventTime)) >70

我们现在需要检查的是尝试放置 =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)
4

1 回答 1

2

你可以替换这个

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)

or use coalescewith a suitably chosen default (in case of NULL):

and TIME_TO_SEC(TIMEDIFF('2012-08-22 06:25:12',
    coalesce(lastEventTime, '1900-01-01')) > 100

尽管合并位仅与WHERE子句相关;SELECT如果NULLlastEventTime是NULL.

于 2012-08-22T11:04:33.213 回答