I want to retrieve a moving average of a cosumes table. I have written the following query but it doesn't work. It retrieves higher averages for the first days. What am I doing wrong?
select c.fecha, count(r.cantidad), avg(r.cantidad)
from
(select distinct fecha
from tb_consumos
where fecha > '2015-02-01') c, tb_consumos r
where datediff(c.fecha, r.fecha)<10
group by c.fecha