目前我正在按总点击量对热门链接进行排序。但我也有每次访问的时间戳。我如何不仅根据总点击量而且根据使用时间对链接进行排序,这样只有最相关的链接才会显示在顶部?
table link_clicks
-----------------
link_id
link_time
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
ORDER BY total_clicks, link_time DESC;