Most common value in an active deck

Just wanted to ask if anyone knows how to find the 5 most frequent values ​​in the colomn model for the active record.

eg,

Country.find(:name)

      

How can I find the 5 most common countries

+3


source to share


1 answer


Use the following



Country.group(:name).order('count_id DESC').limit(5).count(:id)

      

+7


source







All Articles