with 終値推移 as(
select to_date('2006/03/08','YYYY/MM/DD') as 日付, 120 as 終値 from dual
union select to_date('2006/03/09','YYYY/MM/DD') , 480 from dual
union select to_date('2006/03/10','YYYY/MM/DD') , 6000 from dual
union select to_date('2006/03/11','YYYY/MM/DD') ,12000 from dual
union select to_date('2006/03/14','YYYY/MM/DD') ,72000 from dual
union select to_date('2006/03/15','YYYY/MM/DD') ,24000 from dual
union select to_date('2006/03/16','YYYY/MM/DD') , 1200 from dual
union select to_date('2006/03/17','YYYY/MM/DD') , 120 from dual
union select to_date('2006/03/18','YYYY/MM/DD') ,12000 from dual
union select to_date('2006/03/22','YYYY/MM/DD') ,24000 from dual
union select to_date('2006/03/23','YYYY/MM/DD') ,96000 from dual)
select to_char(日付,'YYYY/MM/DD') as 日付,終値,
avg(終値) over(order by 日付 Rows (5-1) Preceding) as 移動平均,
(
1*Lag(終値,4,0) over(order by 日付)+
2*Lag(終値,3,0) over(order by 日付)+
3*Lag(終値,2,0) over(order by 日付)+
4*Lag(終値,1,0) over(order by 日付)+
5*終値) /
(
Lag(1,4,0) over(order by 日付)+
Lag(2,3,0) over(order by 日付)+
Lag(3,2,0) over(order by 日付)+
Lag(4,1,0) over(order by 日付)+
5) as 加重移動平均
from 終値推移
order by 日付;