I need the sql for the following scenario.
I am having some set of selected rows.
For example, Field table, I've filtered the following values
Id | yearId
1 | 1
1 | 2
1 | 3
1 | 4
1 | 5
After filtered, i am doing inner join with the existing table,
Consider Field table having the following columns
Id, yearid, value1, value2, value3, value4,NextYearValue,PreviousYearValue
I need to do inner join with the table and should update like following,
value2 = value2 + value1
value3 = value2 + value3
value4 = value3 + value2
NextYearValue = Value2 + value3 + value4
PreviousYearValue = NextYearValue (should be taken from the previous year value)
value3 should get the updated value2 after calculate value2+value1
value4 should get updated value3 and value2 after finish calculation NextYearValue should get all the udpated value.
PreviousYearValue should get the update value from the previous year value (that means previous row in this scenario I think)