Mysql
 sql >> Database >  >> RDS >> Mysql

Media mobile - MySQL

SELECT AVG(cnt)
  FROM (SELECT COUNT(*) AS cnt
          FROM mytable
         WHERE `date` BETWEEN DATE_SUB(NOW(), INTERVAL 3 MONTH) AND NOW()
      GROUP BY DATE(`date`)) x

Supponendo che tu abbia una tabella mytable con campo date di tipo date , datetime o timestamp