目前,我按总点击次数对热门链接进行排序。但我也有每次访问的时间戳。如何对链接进行排序,不仅要点击总点击次数,还要使用时间,所以只有最相关的链接显示在顶部?
table link_clicks
-----------------
link_id
link_time
答案 0 :(得分:2)
GROUP BY
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
答案 1 :(得分:1)
ORDER BY total_clicks, link_time DESC;