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!

How can I sum the previous row with LAG() function?

Best regards,
I am using the following function (LAG) to sum the previous row: 

(LAG(INV_FINAL, 1, 0) OVER (PARTITION BY DISTRIBUIDORA ORDER BY PERIODO ASC) + LAG(INV_FINAL, 2, 0) OVER (PARTITION BY DISTRIBUIDORA ORDER BY PERIODO ASC)) + INV_FINAL AS RESULT

But it is not giving me the expected result as can you see:
image.pngThe correct result should be :
image.pngI am attentive to your comments, I would be very grateful if you can help me, thank you.

This post has been answered by Paulzip on Oct 7 2021
Jump to Answer
Comments
Post Details
Added on Oct 7 2021
5 comments
6,810 views