Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

How to perform arithmetic calculation on current row based on previous row value?

Richa_ApexNov 27 2021 — edited Nov 29 2021

Hi All,
Happy Thanksgiving!!
I am trying to perform analytical function on sample data provided below:
osamp.png

Below is the snapshot of expected output:
osampmovavg.png

Here is the analytical function I am trying to achieve:

Calculate 5 Days Moving Average only for 5th row.
For 6th row, take the value from 5th row and perform arithmetic operation.
For 7th row, take the value from 6th row and perform arithmetic operation and so on.

Here is the db<>fiddle that I have tried so far.
Below is the snapshot of formula from excel spreadsheet:
Row 5 calculation:

osampmovavgf1.png

Row 6 and Row 7 calculation:

osampmovavgf2.png

osampmovavgf3.png

Similarly for other stock, the calculation remains same and continues:
osampmovavgg1.png

osampmovavgg2.png

Appreciate any help on this. Thanks in advance.
Thanks,
Richa

This post has been answered by mathguy on Nov 27 2021
Jump to Answer

Comments

Post Details

Added on Nov 27 2021
30 comments
2,204 views