Someone
public text v1 · immutableSELECT
a.id,
a.title,
a.category_id,
c.title AS category_title
COUNT(ac.*) AS num_comments
FROM articles a
INNER JOIN articles_category c ON (a.category_id = c.id)
LEFT JOIN article_comments ac ON (a.id = ac.article_id)
WHERE UNIX_TIMESTAMP(datetime) < (NOW() - (60 * 60 * 24 * 7))
GROUP BY a.id
ORDER BY num_comments DESC, datetime DESC
LIMIT 100