Repeating an answer on the following line

  • Thread starter Thread starter Tara
  • Start date Start date
T

Tara

How can I get a calculation from a previous row to show up again in another
row?
I have x and y and need to find a subtotal.

x y subtotal
1 5
2 10 s/b 5 (= y from previous row)
3 15 s/b 10 (=y from previous row)

Thanks,
Tara
 
IS X always sequential with no breaks? IF so this is fairly simple

SELECT Ta.X, Ta.Y, Tb.y
FROM Yourtable as Ta LEFT JOIN YourTable as Tb
ON Ta.x = (Tb.x+1)

IF X is not always sequential then you need something a bit more complex

SELECT Ta.x, Ta.y
, (SELECT First(Tb.Y)
FROM YourTable as Tb
WHERE Tb.x =
(SELECT Max(X)
FROM YourTable as Tc
WHERE Tc.X < Ta.x))
FROM YourTable as Ta

'====================================================
John Spencer
Access MVP 2002-2005, 2007-2008
Center for Health Program Development and Management
University of Maryland Baltimore County
'====================================================
 
Back
Top