Mysql
 sql >> Base de Dados >  >> RDS >> Mysql

Como obter média de acertos entre a data atual e a data postada no MySQL?


Use DATEDIFF função.

Consulta

SELECT id,hits,created,
hits/(DATEDIFF(NOW(),created)) AS Frequency
FROM images
ORDER BY Frequency DESC;

Saída
+----+------+---------------------------------+-----------+
| ID | HITS |         CREATED                 | FREQUENCY |
|----+------+---------------------------------+-----------+
|  2 |    8 | November, 10 2014 05:10:20+0000 |   8       |
|  1 |   10 | November, 07 2014 11:07:57+0000 |   2.5     |
|  3 |   70 |  October, 04 2014 08:04:22+0000 |   1.8421  |
+----+------+---------------------------------+-----------+

Demonstração