在Sql Server中:

declare @totalUsageInSeconds decimal(15,6)
SELECT @totalUsageInSeconds = @totalUsageInSeconds + DATEDIFF(SECOND, @resourceStartTime, @resourceEndTime)


上面的查询以秒为单位给出了正确的日期差异

但在Mysql中,秒数的差异为0.0000 :(请参阅下文)

declare _totalUsageInSeconds decimal(15,6);
SELECT @totalUsageInSeconds = @totalUsageInSeconds + TIME_TO_SEC(TIMEDIFF(_resourceStartTime, _resourceEndTime));


我能知道原因和解决方法吗?

最佳答案

声明变量时,将其设置为NULL。将任何内容添加到NULL时,都会得到一个NULL

更改此行:

declare @totalUsageInSeconds decimal(15,6) = 0;


或添加:

select @totalUsageInSeconds = 0

关于mysql - mysql Timediff()函数返回0.0000,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/17284124/

10-12 16:03