我有一个金融价格时间序列:
date price variance_3 1/1/2012 1,1 n/a 2/1/2012 1,2 n/a 3/1/2012 1,3 4/1/2012 1,3 7/1/2012 1,2 8/1/2012 1.3
我打算使用最近 3 个价格及时计算每个日期的方差。 您是否有机会仅使用 SQL 来完成此任务?
任何提示将不胜感激。
最佳答案
select var_pop(price) as variance
from (
select price
from YourTable
order by
date desc
limit 3
) as SubQueryAlias
关于mysql - 使用 SQL 计算方差,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10316171/