title: Mysql SUM two time and return total duration as days, hours, minutes
body: <p>I want to select duration from several rows grouped by some id. The row contains time (00:04:25), (00:05:25), (12:04:25) (hours, minutes, seconds) etc. How I can sum these rows and return total duration as days, hours , minutes ?
  What I did is this (actually its not me I saw it in other post here on stackoverflow)</p>
  
  <pre><code>$sql = 'SELECT r.*,d.*,        CONCAT(
          FLOOR(HOUR(SEC_TO_TIME(SUM(TIME_TO_SEC(r.duration)))) / 24), "' . $this-     &gt;_translator-&gt;translate(' days ') . '",
          MOD(HOUR(SEC_TO_TIME(SUM(TIME_TO_SEC(r.duration)))), 24), "' . $this-&gt;_translator-&gt;translate(' hours ') . '",
          MINUTE(SEC_TO_TIME(SUM(TIME_TO_SEC(r.duration)))), "' . $this-&gt;_translator-&gt;translate(' minutes ') . '") as total_duration, 
          ROUND(SUM(TIME_TO_SEC(r.duration)/3600)) as total_duration_hours FROM routes r LEFT JOIN drivers d ON d.id = r.driver_id GROUP BY r.driver_id';
  </code></pre>
  
  <p>This is working by not correctly. In r.* are stored also average speed , distance and for example this code returns 2 hours , 23 minutes when it should return 2 hours and 30 minutes. Please help. Thanks !</p>
  
  <p>EDIT:
  Here is some data:</p>
  
  <pre><code> Full texts     id  filename    distance    startRoute  endRoute    duration    avgSpeed    car_id  fromLocation    toLocation  driver_id
  Edit Edit   Copy Copy   Delete Delete   748     GPSdata20140109073948   5.74    2014-01-09 07:40:23     2014-01-09 07:50:38     00:10:15    33.6    20  22, Ulhaus, Langerwehe  27, KÃ¶nigsbenden, Eschweiler   18
  Edit Edit   Copy Copy   Delete Delete   754     GPSdata20140110182521   1.43    2014-01-10 18:25:26     2014-01-10 18:29:31     00:04:05    21.01   18  36, GrÃ¼ner Weg, Aachen     3, Rehmplatz, Aachen    18
  Edit Edit   Copy Copy   Delete Delete   758     GPSdata20140112145245   70.55   2014-01-12 14:54:05     2014-01-12 16:54:42     02:00:37    35.09   23  275, HauptstraÃŸe, Langerwehe   , Pescher Weg, Cologne  18
  Edit Edit   Copy Copy   Delete Delete   759     GPSdata20140113072802   6.17    2014-01-13 07:28:37     2014-01-13 07:37:02     00:08:25    43.98   19  13, BahnhofstraÃŸe, Langerwehe  27, KÃ¶nigsbenden, Eschweiler   18
  </code></pre>
  
  <p>5.74 + 1.43 + 70.55 + 6.17 = 83.9 distance
  33.6 + 21.01 + 35.09 + 43.98 = 33.42 average speed
  So distance / average speed = 2 hours and 30 minutes and i am getting 2 hours and 23 minutes. Where i am doing wrong ?</p>