Hi
I have below code and i want when Account changes cummulation should restart
SQL
SELECT
ROW_NUMBER() OVER (PARTITION BY Account ORDER BY A."Account") AS "Row No",
A."Account" AS "Account",(A."Debit") AS "Debit", (A."Credit") AS "Credit"
From Master AThanks

Emily FosterRank #3,495 · 415 reputationPosted Mar 26, 2025, 6:35 AM EDT
Hi there! It looks like you're working on generating a cumulative total with a reset each time the Account changes in your SQL query. The code snippet you provided is a good starting point.
In SQL, the ROW_NUMBER() function is often used for assigning a unique sequential integer to each row within a partition of a result set. In your case, you are partitioning by the Account column, which means the row number will restart whenever the Account changes.
To calculate the cumulative total that restarts when Account changes, you would need to further build on this query. Here's an example of how you can modify it:
SELECT ROW_NUMBER() OVER (PARTITION BY Account ORDER BY A.Account) AS "Row No", A.Account AS Account, A.Debit AS Debit, A.Credit AS Credit, SUM(A.Debit - A.Credit) OVER (PARTITION BY Account ORDER BY A.Account) AS Cumulative_Total FROM Master A;In this modified query:
- We are still partitioning by the Account column.
- We have added a calculation for the cumulative total using the SUM() window function. This function calculates the running total of Debit minus Credit for each row based on the Account partition and the order specified.
- The Cumulative_Total column will show the running total that restarts whenever the Account changes.
Feel free to test this query with your dataset and adjust it further based on your specific requirements. If you have any more questions or need additional assistance, feel free to ask!
Sangeetha SRank #212 · 11.4K reputationPosted Mar 26, 2025, 7:14 AM EDT
To restart the accumulation when the
Accountchanges, you can use theSUMfunction along with thePARTITION BYclause to calculate cumulative sums forDebitandCreditcolumns. Here's an example of how you can modify your query:SELECT ROW_NUMBER() OVER (PARTITION BY A."Account" ORDER BY A."Account") AS "Row No", A."Account" AS "Account", A."Debit" AS "Debit", A."Credit" AS "Credit", SUM(A."Debit") OVER (PARTITION BY A."Account" ORDER BY A."Account" ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) AS "Cumulative Debit", SUM(A."Credit") OVER (PARTITION BY A."Account" ORDER BY A."Account" ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) AS "Cumulative Credit" FROM Master AAmelia Taylor3 reputationPosted Mar 27, 2025, 8:20 AM EDT
A cumulative sum is calculated by adding all previous values in a sequence to the current value. The sequence is usually a date or time, so the cumulative sum gives you a sum at a certain time. In SQL, this means accessing all the previous rows, summing them, and adding the sum to the current row's value. A cumulative sum is calculated by adding all previous values in a sequence to the current XXL WINE value. The sequence is usually a date or time, so the cumulative sum gives you a sum at a certain time. In SQL, this means accessing all the previous rows, summing them, and adding the sum to the current row's value. Payee cooling period limit is a time and the amount limit set by the bank during which fund transfer is not allowed or allowed till the specified limit, to a newly added payee.
https://wines123.blogspot.com/2024/12/xxl-wine.html