i have data which is below has email and working hours (in hours formate), expecting output of working_hours to hh:mm:ss
select d.email,TRUNCATE(sum(e.hours),2) as "working_hours"
from users d inner join proj_time e on d.id=e.user_id
WHERE start_time BETWEEN CURDATE() - INTERVAL 1 DAY
AND CURDATE() - INTERVAL 1 SECOND
group by d.id,d.email
working_hours | |
---|---|
[email protected] | 5.77 |
[email protected] | 4.24 |
[email protected] | 2.69 |
[email protected] | 6.12 |
i tried below query to change working_hours, BUT getting leading zeros, requested output to remove leading zeros (00:) from working_hours output
select d.email,SEC_TO_TIME(TRUNCATE(sum(e.hours * 60),2)) as "working_hours"
from users d inner join proj_time e on d.id=e.user_id
WHERE start_time BETWEEN CURDATE() - INTERVAL 1 DAY
AND CURDATE() - INTERVAL 1 SECOND
group by d.id,d.email
working_hours | |
---|---|
[email protected] | 00:05:46.20 |
[email protected] | 00:04:14.40 |
[email protected] | 00:02:41.40 |
[email protected] | 00:06:07.20 |
Expected output would be like
working_hours | |
---|---|
[email protected] | 05:46 |
[email protected] | 04:14 |
[email protected] | 02:41 |
[email protected] | 06:07 |
2
Answers
+all thanks for the help. I got answer to my question,
SEC_TO_TIME(ROUND(TRUNCATE(sum(e.hours * 3600),2)))
fiddle