I have Ticker, Dt, [Open], Volume for the input table
Dt is yyyy-mm-dd
I want to return every row where ticker = 'IBM' and also returns the Ticker, Dt, [Open], Volume fields and then include a max column for only say for the previous x days. Let's say 3 days for the sake of not posting too much data.
But I don't know how to get the time frame correct so that the max is only contained to so many days back.
In Table:
Tck Dt [Open] Volume
IBM 2010-05-21 122.160000 6881000
IBM 2010-05-24 125.260000 6876000
IBM 2010-05-25 121.470000 9498800
IBM 2010-05-26 124.890000 9085900
IBM 2010-05-27 125.050000 7726500
What I need:
Tck Dt [Open] Volume Max
IBM 2010-05-21 122.160000 6881000 122.160000
IBM 2010-05-24 125.260000 6876000 125.260000
IBM 2010-05-25 121.470000 9498800 125.260000
IBM 2010-05-26 124.890000 9085900 125.260000
IBM 2010-05-27 125.050000 7726500 125.050000
Here is my current SQL, but obvious doesn't group the Max value correctly.
Select Ticker,
Dt,
[Open],
Volume,
(Select Max([Open]) from Daily_NYSE
where Ticker = 'IBM'
and Dt between DateAdd(Day,-3,'2010-05-27') and '2010-05-27') as 'Max'
from Daily_NYSE
where Ticker = 'IBM'
and Dt between DateAdd(Day,-6,'2010-05-27') and '2010-05-27'
Thanks! Adam