Ruby on rails ActiveRecord:在特定查询中查找UNIQ
我有一个问题,我特别想让uniq学校按年份分组。我好像想不出来。学生有很多人出席,学校有很多学生。下面给出了我每年代表一所学校的时间,但我希望每次代表一所学校的时间都是独一无二的Ruby on rails ActiveRecord:在特定查询中查找UNIQ,ruby-on-rails,activerecord,distinct,Ruby On Rails,Activerecord,Distinct,我有一个问题,我特别想让uniq学校按年份分组。我好像想不出来。学生有很多人出席,学校有很多学生。下面给出了我每年代表一所学校的时间,但我希望每次代表一所学校的时间都是独一无二的 Attendance. joins(:student => :school). order("count_all DESC"). group("schools.name"). group_by_year('attendances.created_at'). where(:students =&
Attendance.
joins(:student => :school).
order("count_all DESC").
group("schools.name").
group_by_year('attendances.created_at').
where(:students => { :school_id => 1}).
count
你用的是什么数据库?Postgres,不过我更喜欢用ActiveRecord查询。“按年分组”方法是一个名为“按星”的gem。请发布您的数据库方案/关系。我在
按星
说明中找不到按年分组。您可能正在使用groupdate
gem?出席人数众多。学校有很多学生。上述情况让我明白,任何一所学校都是按年份分组的。我想得到按年份分组的独特学校的数量。