I apologize if this question has been asked before. I tried to do searches but may not have been using the same wording as others so my searches came up with nothing.
I have a table of just over 6000 rows and I'm trying to do an average of the prior n number of rows of a particular column. In this case, the closing price of a FOREX currency pair. (I know I could use the PHP::Trader but I don't have access to install it on my server.)
I've tried :
SELECT *, (SELECT AVG(close)
FROM `2015_EURUSD_60min`
WHERE (id > (id - 20) AND id <= id)
)
FROM `2015_EURUSD_60min`
This generated the same number for every row and I'm not sure why. Every value in the id
column is sequential. I cleaned up the data to make sure of that.
What did I do wrong in my SELECT
statement?