How to do a sum of previous rows in mysql a sum of previous rows -
this question has answer here:
- create cumulative sum column in mysql 6 answers
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
Post a Comment