我有以下SQL和PHP,似乎并没有给我正确的数字。 (非常高的数字)
我有很多行,带有开始时间和结束时间戳记。 我希望获得这两次之间的平均时间。
即:2小时3分46秒。
这就是我所拥有的。
SELECT AVG(tmp.dd) AS timetook
FROM
( SELECT TIME_TO_SEC(TIMEDIFF(timeclosed, timeanswered)) AS dd
FROM logs
WHERE timeclosed > DATE_SUB(NOW(), INTERVAL 1 DAY)
) tmp;
我要用完全错误的方式进行此操作吗?这里显然有什么问题吗?
while($row = $result->fetch_assoc()) {
$timetoclose = $row['timetook'];
$hours = floor($timetoclose / 3600);
$mins = floor($timetoclose / 60 % 60);
$secs = floor($timetoclose % 60);
$timetoclose = sprintf('%02d Hour(s), %02d Minute(s), %02d Second(s)', $hours, $mins, $secs);
}
欢呼 G
答案 0 :(得分:0)
SELECT SUM(TIMESTAMPDIFF(minute, start_time, end_time)) / COUNT(*) AS avg_minutes
FROM your_table
尝试此查询。