我有一个金融价格时间序列: 日期 价格 方差_31/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 我想使用最近的三个时间点来计算每个日期的方差。 您认为只用SQL能完成这个任务吗? 如果您有任何提示,将不胜感激。
select var_pop(price) as variance from ( select price from YourTable order by date desc limit 3 ) as SubQueryAlias
VAR_POP
(或VAR_SAMP
,取决于哪个在后面)而不是STDDEV
,因为OP要求方差... - eggyal