在 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));
我能知道原因以及如何解决问题吗?