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

Come ottenere risultati medi tra la data corrente e la data di pubblicazione in MySQL?

Usa DATEDIFF funzione.

Interrogazione

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

Risultato

+----+------+---------------------------------+-----------+
| 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  |
+----+------+---------------------------------+-----------+

Demo