当前位置: 动力学知识库 > 问答 > 编程问答 >

sql - Calculating running average with sqlite

问题描述:

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
)
分享给朋友:
您可能感兴趣的文章:
随机阅读: