我怎么能指望的有在ROR某一特定领域的唯一值的记录数?领域、我怎么能、ROR、唯一值

2023-09-09 22:09:18 作者:宁做不懂是是非非的孩子

我有一个包含日期字段的记录集,要确定有多少独特的日期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)
 
精彩推荐
图片推荐