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.
我有以下内容:
Groups: id, title GroupMembers: id, group_id, name
组有很多 group_members
如何查询数据库以获取至少有 2 个 GroupMembers 的所有组?
谢谢
试试这个:
Group.joins("( SELECT group_id FROM group_members GROUP BY group_id HAVING COUNT(1) > 1 ) a ON a.member_id = groups.id")