Reputation: 71
I am using the following code to calculate a running average:
SELECT AVG(close) FROM daily
ORDER BY datum DESC
LIMIT 50
for a 50-day average. However, it doesn't seem to work. I can change LIMIT
to 5
, 10
, 20
. The result is always the same. Is the LIMIT
just a visual limit maybe?
Upvotes: 2
Views: 1222
Reputation: 750
LIMIT
restricts your result set, not the set you're averaging over. You'd want something like
SELECT AVG(close) FROM
(
SELECT close FROM daily ORDER BY datum DESC LIMIT 50
)
Upvotes: 4