1
我想通过模型关系的汇总值进行查询。 举例来说,我应该只会得到的帖子它有两个日期之间的最后一条评论。汇总关系的雄辩查询
SELECT posts.*, MAX(comments.created_at)
as max FROM posts
JOIN comments ON (comments.post_id = posts.id)
GROUP BY posts.id HAVING max > '2014-01-01 00:00:00' AND max < '2014-02-01 00:00:00'