Homepage |
IT Services |
Consulting |
Training |
Get help now |
Application Development |
Support and Downloads |
Contact Us |
Send us a comment or question |
Applications |
MS Access |
MS Excel |
Coding and Macros |
Excel VBA |
Creating Cumulative (Running) Sum - SQL
One of the most simple ways to have the query make an additional running sum to a field. This requires the table to have distinct values only on a keyfield (in this case Mth)
SELECT Totals2.Product, Totals2.Mth, Totals2.Qty, (SELECT SUM(Qty) FROM Tbl_Totals Totals1 where Totals1.Mth <= Totals2.Mth) AS RunningSum FROM Tbl_Totals AS Totals2 ORDER BY Totals2.Mth;
Result:
Last modified on August 19 2015