Hvis du vil have det glidende gennemsnit for hver dato, så prøv dette:
SELECT date, SUM(close),
(select avg(close) from tbl t2 where t2.name_id = t.name_id and datediff(t2.date, t.date) <= 9
) as mvgAvg
FROM tbl t
WHERE date <= '2002-07-05' and
name_id = 2
GROUP BY date
ORDER BY date DESC
Den bruger en korreleret underforespørgsel til at beregne gennemsnittet af 9 værdier.