In my blog , I display in the right navigation window the 10 most popular articles in terms of page hits. Here is how I understand it:
SELECT * FROM entries WHERE is_published = 1 ORDER BY hits DESC, created DESC LIMIT 10
What I would like to do is show the top 10 results per page per day. I am using MySQL. Is there a way to do this in the database?
BTW, the created field is a datetime.
UPDATE: I guess I didn’t explain. What I want is a 10,000 hit blog post that was published 1,000 days ago to be as popular as a 10 hit blog post that was posted 1 day ago. In pseudo code:
ORDER BY hits / days since posting
... where hits is just an int that increments every time a blog post is viewed.
OK, here is what I will use:
SELECT *, AVG( hits / DATEDIFF(NOW(), created) ) AS avg_hits FROM entries WHERE is_published = 1 GROUP BY id ORDER BY avg_hits DESC, hits DESC, created DESC LIMIT 10
Thanks Steven! (I like this site ...)
source share