Trying to return stock price data and moving average for a list of stocks.
Posted on 2004-11-16
I'm trying to return the opening price(PX_OPEN), closing price (PX_LAST), and a 3-day moving average of the closing price (just for example) from a table of stock price information structured as:
To be clear, let's say that I want to return this info (open, close, 3-day average) for the most recent 30 days. I've tried the following to get this info for ALL days (just for starters):
SELECT ticker, pdate, PX_OPEN, PX_LAST, AVG(PX_LAST)
WHERE pdate Between DATEADD(d,-3,pdate) And pdate
GROUP BY ticker;
and I'm getting an error "You tried to execute a query that does not include the specified expression 'pdate' as part of an aggregate function." Not sure what's going wrong here.