PHP和MySQL -流行的链接,基于点击和时间

时间:2022-04-11 23:01:43

At the moment I am sorting popular links by total clicks. But I also have timestamps for each visit. How can I sort links not only by total clicks but also using time, so only the most relevant are showed at the top?

目前,我正在按总点击数对流行链接进行排序。但是我每次都有时间戳。我如何排序链接,不仅是通过总点击,而且使用时间,所以只有最相关的显示在顶部?

table link_clicks
-----------------
link_id
link_time

2 个解决方案

#1


2  

GROUP BY link_id and just use a date constraint in your WHERE clause:

通过link_id进行分组,并在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


1  

ORDER BY total_clicks, link_time DESC;

#1


2  

GROUP BY link_id and just use a date constraint in your WHERE clause:

通过link_id进行分组,并在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


1  

ORDER BY total_clicks, link_time DESC;