How to do a sum of previous rows in mysql a sum of previous rows -


this question has answer here:

first of sorry english

i try find requete calculate sum of values in different rows :

row1    result 2          2 5          7 7          14 

assuming first row defines ordering, can correlated subquery:

select r.row1,        (select sum(t2.row1) requete r2 r2.row1 <= r.row1) cumesum requete r; 

for larger table, might inefficient, , variables improve performance:

select r.row1,        (@sum := @sum + r.row1) cumesum requete r cross join      (@sum := 0) params order r.row1; 

note in both cases column used ordering rows not need same column cumulative sum calculation.


Comments

Popular posts from this blog

android - questions about switching from C2DM to GCM -

c++ - Qt setGeometry: Unable to set geometry -

batch file - How to extract all multi-volume RAR archives from subfolders of a folder? -