Quantcast
Channel: Teradata Forums - All forums
Viewing all articles
Browse latest Browse all 27759

using a calculation done in the previous row in this row's calculation - forum topic by tbenard

$
0
0

I am doing a query in which the results of a previous row calculation are used in the next row calculation (recursive I guess).
 
For example the results should look like this:
 

Item

Loc

Week

A

B

C

Inventory (Prev Inv + A + B - C)

 

1111

aaaa

201301

100

40

60

80

First time prev inv is null

1111

aaaa

201302

30

200

100

210

 

 
So I can use
MIN(Inventory) OVER(ORDERBY item, loc, week ROWSBETWEEN 1 PRECEDINGAND 1
       PRECEDING) as PrevInv
 
And the second row will be good (PrevInv + A + B – C)
 
However on the rest of the rows I cannot use the previous row's created Inventory value.

Forums: 

Viewing all articles
Browse latest Browse all 27759

Trending Articles