Get the Running Total in Oracle

This very frequent needful thing for developers as they need to create so many reports based on this concept.

For this you will have to use one of the window functions in oracle which is ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW.

This would add each and every vale with previous value and give like Running Total.

Query for this,

SELECT PRODUCT_NO,PL_NO, UNRESTRICTED_QTY,

SUM(UNRESTRICTED_QTY) OVER (ORDER BY PRODUCT_NO ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) RUNNING_TOTAL

FROM PRODUCT_LOCATION

WHERE CLIENT_C=UPPER(‘MSWG’) AND UNRESTRICTED_QTY>0 AND LOCATION_NO=’RECEIPT_BAY‘

row in the result set and adding up the values with currently reading value which is specified by CURRENT ROW up to last record of the record set.

And ordering results by PRODUCT_NO

The result of the above query shown below.





Comments

Popular posts from this blog

SQL SERVER – TRIM() Function – UDF TRIM()