![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
I have a table that contains the fields PERIOD, STOCK, NEW_UNITS, CHURN_RATE. STOCK is only available for a given start period. I want to update the expected stock of the next periods. Is there a way that in pure SQL (without PL SQL and a cursor) I can calculate STOCK of PERIOD (N) = STOCK of PERIOD (N-1) * (1-CHURN_RATE) + NEW_UNITS |
#3
| |||
| |||
|
|
Hans Mayr escribió: I have a table that contains the fields PERIOD, STOCK, NEW_UNITS, CHURN_RATE. STOCK is only available for a given start period. I want to update the expected stock of the next periods. Is there a way that in pure SQL (without PL SQL and a cursor) I can calculate STOCK of PERIOD (N) = STOCK of PERIOD (N-1) * (1-CHURN_RATE) + NEW_UNITS Perhaps you can use the LAG function: |
#4
| |||
| |||
|
|
Hello, I have a table that contains the fields PERIOD, STOCK, NEW_UNITS, CHURN_RATE. STOCK is only available for a given start period. I want to update the expected stock of the next periods. Is there a way that in pure SQL (without PL SQL and a cursor) I can calculate STOCK of PERIOD (N) = STOCK of PERIOD (N-1) * (1-CHURN_RATE) + NEW_UNITS ? Thanks and best, Hans |
#5
| |||
| |||
|
|
"Hans Mayr" <mayr1972 (AT) gmx (DOT) de> a écrit dans le message de news: 175b9dc2-db4a-4fab-855a-276439402249...oglegroups.com... | Hello, | | I have a table that contains the fields PERIOD, STOCK, NEW_UNITS, | CHURN_RATE. STOCK is only available for a given start period. I want | to update the expected stock of the next periods. Is there a way that | in pure SQL (without PL SQL and a cursor) I can calculate | | STOCK of PERIOD (N) = STOCK of PERIOD (N-1) * (1-CHURN_RATE) + | NEW_UNITS | | ? | | Thanks and best, | | Hans If you post a test case (create table and insert statements) maybe we can help more. It seems to be a good example for MODEL clause although it may be possible to do it with CONNECT BY depending on the exact case. Regards Michel |
![]() |
| Thread Tools | |
| Display Modes | |
| |