Mysql
 sql >> Datenbank >  >> RDS >> Mysql

Wie bekomme ich durchschnittliche Treffer zwischen dem aktuellen Datum und dem geposteten Datum in MySQL?

Verwenden Sie DATEDIFF Funktion.

Abfrage

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

Ausgabe

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