Create sample table with data:

Cumulative SUM column using MySQL Variable:

CREATE TABLE SimpleTable
(
Id INT
,SumValue INT
);
INSERT INTO SimpleTable
VALUES
(1,100),(2,150),(3,200)
,(4,250),(5,75),(6,500);
SELECT * FROM SimpleTable
Output:
Cumulative SUM column using MySQL Variable:
set @csum := 0;
select id, SumValue, (@csum := @csum + SumValue) as Cumulative_sum
from SimpleTable
order by id;
Output:
0 Comments