PHP and MySQL - popular click and time based links

I am currently sorting popular links by common clicks. But I also have timestamps for every visit. How can I sort links not only by general clicks, but also by time, so only the most relevant ones are displayed in the upper part?

table link_clicks
-----------------
link_id
link_time
+3
source share
2 answers

GROUP BY link_idand just use the date limit in your sentence WHERE:

SELECT link_id, COUNT(*) AS num_clicks
FROM link_clicks
WHERE link_time >= '2011-05-20'
GROUP BY link_id
ORDER BY num_clicks DESC
+2
source
ORDER BY total_clicks, link_time DESC;
+1
source

All Articles