How can I count the number of records that have a unique value in a particular field in ROR?

前端 未结 7 1078
予麋鹿
予麋鹿 2020-12-04 21:21

I have a record set that includes a date field, and want to determine how many unique dates are represented in the record set.

Something like:

Record         


        
7条回答
  •  生来不讨喜
    2020-12-04 21:58

    the latest #count on rails source code only accept 1 parameter. see: http://api.rubyonrails.org/classes/ActiveRecord/Calculations.html#method-i-count

    so I achieved the requirement by

    Record.count('DISTINCT date')
    

提交回复
热议问题