1
我有3個表格:組,用戶和帖子。帖子有一個user_id,用戶有一個group_id。我想知道哪個組具有日期範圍內的頂級海報,最好只使用ActiveRecord。我認爲這個查詢做的工作:有沒有辦法將其轉換爲rails arel查詢?或者更好的方式來做這個查詢?
select g_id, count(p_id) as posts_count
from (
select users.group_id as g_id, posts.id as p_id
from users inner join posts
on users.id = posts.user_id
where users.group_id is not null
and posts.created_at > :since
and posts.created_at <= :until
) as foo
group by g_id
order by posts_count desc limit 1;
有人可以幫我翻譯它爲紅寶石?