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'