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
Table Sample Data
Query to get Cumulative Sum of Amount on the basis of Type
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, AMOUNTOutput
No comments:
Write Comments