Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
目前,我正在按总点击次数对热门链接进行排序。但我也有每次访问的时间戳。如何不仅按总点击次数而且按时间对链接进行排序,以便仅在顶部显示最相关的链接?
table link_clicks ----------------- link_id link_time
GROUP BY link_id并在您的WHERE子句中使用日期约束:
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;