title: How can I create a column with a running sum of the wordcount using mysql?
body: <p>I'm using the following sql to combine 2 tables and then count the results</p>
  
  <pre><code>SELECT td.word, COUNT( instance ) AS wordcount
          FROM ws_words td
          LEFT JOIN ws_missed_words t ON ( t.wordID = td.wordID )
          WHERE quizID =1
          GROUP BY td.word
  </code></pre>
  
  <p>The results give</p>
  
  <pre><code>*****************************
  |  word  |      wordcount   |
  *****************************
  |  list  |         3        |
  |  miss  |         1        |
  |  skip  |         1        |
  | another|         0        |
  </code></pre>
  
  <p>I'd like to add one more column to this. I'd like to do a running sum of the wordcount column and put it into its own column (called total) as shown below.</p>
  
  <p><strong>wanted results</strong></p>
  
  <pre><code> ****************************************************
      |  word  |      wordcount   |   totalwordcount  |
      *************************************************
      |  list  |         3        |     3             |
      |  miss  |         1        |     4             |
      |  skip  |         1        |     5             |
      | another|         0        |     5             |
  </code></pre>
  
  <p>I've tried the following</p>
  
  <pre><code>SELECT td.word, COUNT( instance ) AS wordcount, SUM(wordcount) AS totalwordcount
  FROM ws_words td
  LEFT JOIN ws_missed_words t ON ( t.wordID = td.wordID )
  WHERE quizID =1
  GROUP BY td.word
  </code></pre>
  
  <p>but I get the error</p>
  
  <pre><code>#1054 - Unknown column 'wordcount' in 'field list'
  </code></pre>
  
  <p>So next I tried</p>
  
  <pre><code>SELECT atable.word, atable.wordcount, SUM(atable.wordcount) AS totalwordcount FROM
  (SELECT td.word, COUNT( instance ) AS wordcount
  FROM ws_words td
  LEFT JOIN ws_missed_words t ON ( t.wordID = td.wordID )
  WHERE quizID =1
  GROUP BY td.word) AS atable
  </code></pre>
  
  <p>but I get something like this</p>
  
  <pre><code>************************************************
  |  word  |      wordcount   |   totalwordcount |
  ************************************************
  |  list  |         1        |         5        |
  </code></pre>
  
  <p><strong>QUESTION</strong></p>
  
  <p>How can I create a column with a running sum of the wordcount?</p>
  
  <p><strong>UPDATE</strong> STRAWBERRY'S METHOD gives me the below code</p>
  
  <hr>
  
  <pre><code>|  word  |      wordcount   |   running         |
  *************************************************
  | another|         0        |     1             |
  |  miss  |         1        |     2             |
  |  skip  |         1        |     3             |
  |  list  |         3        |     4             |
  </code></pre>
  
  <p>It seems to be ranking each word, so the lowest wordcount starts at 1, then if there are 2 words of equal wordcount it lists them in alphabetical order. </p>