我的部分mysql查询如下所示
Select sNumber From serial Where
TIME_TO_SEC( TIMEDIFF( '2014-12-03 14:19:11', lastEventTime ) ) >=300
如果时间差异与lastEvenTime相比超过300秒,则可以生成结果。我现在的问题是,如果lastEventTime是默认值“0000-00-00 00:00:00”,那么它将我作为空结果发送给我。如何确保如果它的默认值,那么我也想显示结果?
答案 0 :(得分:1)
试试这个:
Select sNumber From serial Where
TIME_TO_SEC(IF(lastEventTime='0000-00-00 00:00:00',300,
TIMEDIFF('2014-12-03 14:19:11', lastEventTime)) ) >=300
如果有帮助,请告诉我。
修改强>
如果您将字段更改为null,请尝试以下操作:
Select sNumber From serial Where
TIME_TO_SEC(IF(lastEventTime IS NULL,300,
TIMEDIFF('2014-12-03 14:19:11', lastEventTime)) ) >=300
编辑2
试试这个:
Select sNumber From serial Where
IF(lastEventTime IS NULL,300,
TIME_TO_SEC(TIMEDIFF('2014-12-03 14:19:11', lastEventTime))) >=300