Wednesday, 25 July 2018

MySQL: How to generate Cumulative Sum Column?

In this post, I am populating a cumulative SUM column for a table of MySQL.
For example, If we are working with sales and inventory management domain, every day we need to calculate cumulative sum of different columns like tock value, profit figure, expense figure.
Generally, we can use this kind of demonstration for report purpose only and if it is required to store, we can populate and store for permanent use.
Below is a small demonstration:
Create sample table with data:
Populate cumulative SUM column using MySQL Variable:
Populate cumulative SUM column using MySQL Correlated query:
The Result:


MySQL Cumulative Sum

0 comments:

Post a Comment