Jump to content


Photo

select sum(time) from table


  • Please log in to reply
3 replies to this topic

#1 Jgl_73

Jgl_73
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 14 November 2003 - 11:53 AM

I have problems summing up times using the following select:

$Query ="SELECT SUM(TimeField) from myTable";

I have tried to set to TimeField to be a TIME and a TIMESTAMP field.
What MySQL does it summarizes the time, but it counts to 100 on seconds and minutes.

1) 00:45:50
2) 00:20:21 => Output: 6571
I would like perform a select where I get to total time from all the records in HH:MM:SS format. Can anyone help please!

#2 shivabharat

shivabharat
  • Members
  • PipPipPip
  • Advanced Member
  • 371 posts
  • LocationChennai, India

Posted 14 November 2003 - 01:32 PM

Try this

select SEC_TO_TIME(sum(TIME_TO_SEC(time_filed))) from <table_name>;

Knowledge --- Reading Enriches Mind But Sharing Enhances It.[br][br]Note: Before you request help enusre that you have had a look at the tutorials @phpfreaks

#3 Jgl_73

Jgl_73
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 14 November 2003 - 02:17 PM

Thanks a lot!

select SEC_TO_TIME(sum(TIME_TO_SEC(time_filed))) from table_name>;
did not work but by adding AS Answer like

select SEC_TO_TIME(sum(TIME_TO_SEC(time_filed))) AS Answer from table_name>;

I got it to work

#4 shivabharat

shivabharat
  • Members
  • PipPipPip
  • Advanced Member
  • 371 posts
  • LocationChennai, India

Posted 14 November 2003 - 03:24 PM

Glad to know that it helped you a bit :)
Knowledge --- Reading Enriches Mind But Sharing Enhances It.[br][br]Note: Before you request help enusre that you have had a look at the tutorials @phpfreaks




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users