In this post, I am sharing the code to calculate Cumulative sum in Oracle
Query to get Cumulative Sum of Amount on the basis of Type
Output
Table Sample Data
Query to get Cumulative Sum of Amount on the basis of Type
1 2 3 4 5 6 7 8 | SELECT NUM , DECODE(TYPE, 'DR' , AMOUNT) , DECODE(TYPE, 'CR' , AMOUNT) , SUM (DECODE(TYPE, 'CR' , AMOUNT, -1 * AMOUNT)) OVER ( ORDER BY NUM ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) AS BALANCE FROM TBL GROUP BY NUM, TYPE, AMOUNT |
No comments:
Write Comments