我想总结所有时间差异,以显示志愿者的总工作时间.获得时间差的结果集很容易:
Select timediff(timeOut,timeIn)
FROM volHours
WHERE username = 'skolcz'
它给出了按小时计算的时间列表,但是我希望将它总计为总计.
所以如果结果集是:
12:00:00
10:00:00
10:00:00
08:00:00
这将只有40个小时.
这有一种方法可以做:
SELECT SUM(Select timediff(timeOut,timeIn)
FROM volHours
WHERE username = 'skolcz') as totalHours
?
最佳答案
Select SEC_TO_TIME(SUM(TIME_TO_SEC(timediff(timeOut,timeIn)))) AS totalhours
FROM volHours
WHERE username = 'skolcz'
如果不是那么可能:
Select SEC_TO_TIME(SELECT SUM(TIME_TO_SEC(timediff(timeOut,timeIn)))
FROM volHours
WHERE username = 'skolcz') as totalhours