Hi,
based on a transaction table I would like to display a chart showing cumulative income and expense
values. No idea how to go about it
the query in mind would look like the image below
For the chart I only would need the cum values for any given month end
Anyone having an example of cum s in sql ?
Thanks
[Solved] How to calculate cumulative values in queries
[Solved] How to calculate cumulative values in queries
- Attachments
-
- Screen Shot 05-26-21 at 08.17 PM.PNG (4.12 KiB) Viewed 3332 times
Last edited by gkick on Thu May 27, 2021 6:17 am, edited 2 times in total.
Libre Office 6.4.6 on Windows 10 HSQL 2.51 backend
Re: How to calculate cumulative values in queries
Here is one method.
Code: Select all
SELECT t1.id, t1.income, t1.expense, SUM(t2.income) AS Cum_Income, SUM(t2.expense) AS Cum_Exp
FROM Money t1 INNER JOIN Money t2 ON t1.id >= t2.id
GROUP BY t1.id, t1.income, t1.expenseOpenOffice 4.1 on Windows 10 and Linux Mint
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
Re: How to calculate cumulative values in queries
That's great, thank you so much!!!
Libre Office 6.4.6 on Windows 10 HSQL 2.51 backend