Hi
I have below code and i want to display cummulative totals also.
SELECT
A."Account" AS "G/l Account",(A."Debit") AS "Debit", (A."Credit") AS "Credit"
From Masters A
group by A."Account"
Thanks
Hi
I have below code and i want to display cummulative totals also.
SELECT
A."Account" AS "G/l Account",(A."Debit") AS "Debit", (A."Credit") AS "Credit"
From Masters A
group by A."Account"
Thanks
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Ramco RamcoPosted Mar 26, 2025, 10:32 AM
Hi Imram
With same Account it shows same Cummulative Total. IT should be row number wise
Thanks
Muhammad Imran AnsariPosted Mar 26, 2025, 10:25 AM
Hello Ramco,
To display cumulative totals along with your grouped data, you need to use the SUM() window function instead of
GROUP BY. TheGROUP BYstatement currently aggregates data per account but does not allow cumulative calculations.Good Luck!
Eliana BlakePosted Mar 26, 2025, 7:50 AM
Thank you for sharing your query regarding displaying cumulative totals in SQL. To calculate cumulative totals in SQL, you can use window functions like `SUM()` in conjunction with `OVER()` clause. Here's an example of how you can modify your SQL code to include cumulative totals:
In this adjusted query, the `SUM(A."Debit" - A."Credit") OVER (ORDER BY A."Account")` expression calculates the cumulative total by summing up the differences between debits and credits in the specified order.
By incorporating this modification, you will now have an additional column showing the cumulative total. This can provide valuable insights into the running total of your financial data. If you run this query on your dataset, you should see the cumulative totals alongside the individual debit and credit amounts for each account.
I hope this explanation helps you achieve the desired result in displaying cumulative totals in your SQL query. If you have any further questions or need more assistance with this topic or any other, feel free to ask!