问题描述:

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?

网友答案:

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
)
相关阅读:
Top