Create a Cumulative Sum Column in MySQL

Posted by Kirk on Stack Overflow See other posts from Stack Overflow or by Kirk
Published on 2010-04-01T21:50:17Z Indexed on 2010/04/01 21:53 UTC
Read the original article Hit count: 342

Filed under:
|

I have a table that looks like this:

id   count
1    100
2    50
3    10

I want to add a new column called cumulative_sum, so the table would look like this:

id   count  cumulative_sum
1    100    100
2    50     150
3    10     160

Is there a MySQL update statement that can do this easily? What's the best way to accomplish this?

© Stack Overflow or respective owner

Related posts about mysql

Related posts about mysql-query