ArrayOutOfBound
ArrayOutOfBound

Reputation: 2628

Summing Hours and Minutes in MySQL query

After running a query I am getting a Column Like one Below in MySQL

TimeDiff
03:45:07
03:28:59
00:36:16
00:59:42
02:44:18

Now I want to Sum up the Time together in the Same Query. A Sample Query is as given below

SELECT timediff(OutTime, InTime) AS TimeDiff
  FROM Table1 

I tried Sum and SEC_TO_TIME but I am using in the wrong way.

Kindly let me know how to sum up the time to get 11:53:33

Upvotes: 1

Views: 1160

Answers (1)

502_Geek
502_Geek

Reputation: 2126

SELECT
  SEC_TO_TIME(SUM(tbl.TimeDiff)) as TimeDifferent
FROM
  (SELECT TIME_TO_SEC(timediff(OutTime, InTime)) AS TimeDiff
   FROM Table1) as tbl

Upvotes: 1

Related Questions