title: Sum values (same column)
body: <p>I have this table</p>
  
  <pre><code>user_id     time_completed
      4           86.30887
      5           57.81364
      5           35.50281
      5           10.00000
      5           74.19355
      5           31.91489
      6           15.00000
      6           20.50000
  </code></pre>
  
  <p>I need to sum all the time for each user, something like this:</p>
  
  <pre><code>user_id     time_completed
  4           86.30887
  5           209.42489
  6           35.50000
  </code></pre>
  
  <p>This is how I get the first table:</p>
  
  <pre><code>$result = mysql_query ("SELECT user_id,time_completed FROM `mytable` ORDER BY  `mytable`.`user_id` ASC;" )
  </code></pre>
  
  <p>Any idea?</p>
  
  <p><strong>EDIT:</strong>
  What if I need to replace user_id for the name in the following table (db_users)?</p>
  
  <pre><code>id          username
  1           admin
  2           peter
  3           tom
  4           user
  5           joey
  6           helen
  </code></pre>
  
  <p><strong>EDIT2:</strong>
  I've modified this table (db_users) and I want country also appears in the query.</p>
  
  <pre><code>id          username        country
  1           admin           ES
  2           peter           IT
  3           tom             US
  4           user            GB
  5           joey            GE
  6           helen           FR
  </code></pre>
  
  <p>Like this:</p>
  
  <pre><code>user_id     time_completed      country
  4           86.30887            GB
  5           209.42489           GE
  6           35.50000            FR
  </code></pre>
  
  <p>Take a look here: <a href="http://sqlfiddle.com/#!2/24d1b/11" rel="nofollow">http://sqlfiddle.com/#!2/24d1b/11</a></p>