こんなサイトを見つけた。時間のあるときに読んで勉強する。
SQLパズルは自分も持っていて大変ためになった。

select hi, code, owari,
(select avg(b.owari) from kabuka b
where b.code=a.code
and (select count(*)
from kabuka c
where c.code=a.code and c.hi between b.hi and a.hi) between 1 and 25
having count(*) = 25) as "25日移動平均"
from kabuka a
where a.hi = '2006-10-12'