title: Cumulative sum query on foreign key
body: <p>I want to write a query for cumulative sum in MYSQL. I have a foreign key in my table and I want to add their hours as a cumulative sum.</p>
  
  <p>Table 1</p>
  
  <pre><code>id(not primary key)   Hours
  1                       4
  2                       4
  1                       5
  </code></pre>
  
  <p>I have tried this query</p>
  
  <pre><code>select spent_hours := spent_hours + hours as spent 
  from time 
  join (select spent_hours := 0) s
  </code></pre>
  
  <p>I am getting this</p>
  
  <pre><code>id(not primary key)    hours    spent
  1                       4        4
  2                       4        8
  1                       5        13
  </code></pre>
  
  <p>But I want this result:</p>
  
  <pre><code>id(not primary key)    Hours spent
  1                       4    4
  2                       4    4
  1                       5    9
  </code></pre>