我有一个包含日期字段的记录集,要确定有多少独特的日期psented的记录集重$ P $。
I have a record set that includes a date field, and want to determine how many unique dates are represented in the record set.
是这样的:
Record.find(:all).date.unique.count
但当然,这似乎并没有工作。
but of course, that doesn't seem to work.
什么你要去的是SQL语句:
What you're going for is the following SQL:
SELECT COUNT(DISTINCT date) FROM records
ActiveRecord的是这个内置的:
ActiveRecord has this built in:
Record.count('date', :distinct => true)