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_idWHERE節で日付制約を使用するだけです。
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;