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!

Is it possible to lag over (the same) calculated column?

Wendy TrompNov 1 2006 — edited Nov 6 2006
In my sql query I want to calculate a column based on the previous value of that same column plus some other value.
Example: I have columns A B C and D. The value of D can be the following:
- The same value as A
- The previous value of D plus B
- The previous value of D plus C

I tried to use lag to do this but it cannot lag over the same column I am calculating at that time, so
lag(D,1) order by (whatever) as D
will not work.

Right now I am using a package to remember the value, is that the only way?
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 4 2006
Added on Nov 1 2006
17 comments
6,530 views