I want to sum a column (duration) by a query statement. For example, 1:42:00, 2:53:00, 4:12:00 , …
When I use this query (sum(duration)), it gives me a number. But it is not exact, I guess it is a INT. How to get it in time format?
Thanks in advance
SUM is a numeric addition function, it will not work with time.
You can convert the times to seconds and sum that. Something like this might work:
SELECT SEC_TO_TIME( SUM( TIME_TO_SEC( `duration` ) ) ) AS total_time FROM your-table-name;
It will give you the total seconds converted to time. Not tested, but, should work. It basically converts all
of your times to seconds, sums them and then converts them to a time field. Should work.
Thanks for your support. that’s perfect.