Jojo George
Jojo George

Reputation: 159

how to sum different values of time type in sql table

my query :

 SELECT (
 `total_hours`
)
FROM work_details
WHERE  `employee_id` =  '28'
AND DATE
BETWEEN  '2012-02-01'
AND  '2012-02-01'

LIMIT 0 , 30

// Which takes total hours worked for a given employee in given date from database table work_details

result:

total_hours
            02:27:29
            00:13:56
            03:03:49
            00:00:03
            00:30:20
            01:04:13

//result shows the times an employee worked in a given date,I need to get the total of these values to find total working hour in a given date.

how to get sum of these values in a field???

if i use sum(total_hours) result would be

sum( total_hours ) 
67870 

and that is not correct.I require it in time type itself.

And i have one more help needed, this query worked because i gave same date for the BETWEEN clause.

DATE
    BETWEEN  '2012-02-01'
    AND  '2012-02-01'

But i need to calculate total working hours of days in a given range , say

DATE
    BETWEEN  '2012-02-01'
    AND  '2012-02-29'

Since a given date has multiple total hours entry , i need get total hours for each distinct day.Help??

Upvotes: 2

Views: 972

Answers (1)

LeleDumbo
LeleDumbo

Reputation: 9340

try this (taken from here):

SELECT SEC_TO_TIME(SUM(TIME_TO_SEC(`total_hours`))) ... -- rest of your query

Upvotes: 4

Related Questions