我应该如何使用分析来给我一个样本量变化的滚动平均值?
create table MyVals (Item_no char(10), epoch number, Yield number, Skip_Period char(1), Reset_Period char(1));
insert into MyVals values ('A00001',1705, 12, 'N','N'); /* 17.18181818 average of epochs 1705..1610 & 1607..1606 */
insert into MyVals values ('A00001',1704, 13, 'N','N'); /* 19.45454545 average of epochs 1704..1610 & 1607..1605 */
insert into MyVals values ('A00001',1703, 9, 'N','N'); /* 20.36363636 average of epochs 1703..1610 & 1607..1604 */
insert into MyVals values ('A00001',1702, 11, 'N','N'); /* 21.5 average of epochs 1702..1610 & 1607..1604 */
insert into MyVals values ('A00001',1701, 4, 'N','N'); /* 22.66666667 average of epochs 1701..1610 & 1607..1604 */
insert into MyVals values ('A00001',1613, 16, 'N','N'); /* 25 average of epochs 1613..1610 & 1607..1604 */
insert into MyVals values ('A00001',1612, 33, 'N','N'); /* 26.28571429 average of epochs 1612..1610 & 1607..1604 */
insert into MyVals values ('A00001',1611, 2, 'N','N'); /* 25.16666667 average of epochs 1611..1610 & 1607..1604 */
insert into MyVals values ('A00001',1610, 1, 'N','N'); /* 29.8 average of epochs 1610 & 1607..1604 */
insert into MyVals values ('A00001',1609, 66, 'Y','N'); /* 37 average of epochs 1607..1604 */
insert into MyVals values ('A00001',1608, 23, 'Y','N'); /* 37 average of epochs 1607..1604 */
insert into MyVals values ('A00001',1607, 22, 'N','N'); /* 37 average of epochs 1607..1604 */
insert into MyVals values ('A00001',1606, 66, 'N','N'); /* 42 average of epochs 1606..1604 */
insert into MyVals values ('A00001',1605, 37, 'N','N'); /* 30 average of epochs 1605..1604 */
insert into MyVals values ('A00001',1604, 23, 'N','Y'); /* 23 average of epochs 1604 */
insert into MyVals values ('A00001',1603, 77, 'N','N'); /* 44.83333333 average of epochs 1603..1511 */
insert into MyVals values ('A00001',1602, 15, 'N','N'); /* 38.4 average of epochs 1602..1511 */
insert into MyVals values ('A00001',1601, 82, 'N','N'); /* 44.25 average of epochs 1601..1511 */
insert into MyVals values ('A00001',1513, 4, 'N','N'); /* 31.66666667 average of epochs 1513..1511 */
insert into MyVals values ('A00001',1512, 7, 'N','N'); /* 45.5 average of epochs 1512..1511 */
insert into MyVals values ('A00001',1511, 84, 'N','N'); /* 84 average of epochs 1511 */
如何获得之前最多 13 条记录的平均产量,其中 Skip_Period = 'N' 而 Reset_Period = 'N'
因此,平均值的窗口会根据 skip_Period 和 Reset_Period 的值根据以下规则发生变化:
如果一行的 Reset_Period = 'Y',则不要返回该记录以外的任何位置。如果一行有 Skip_period = 'Y',则从平均样本中排除该时段
我不知道如何在表达式之间创建一个范围,这将为我提供使用分析所需的滚动平均值。
欢迎任何建议:)