Ruby-on-rails – rails 3 Select different sequences by the number of occurrences

In one of my models, I have a country column. How would I choose the top 3 countries/regions based on the number of models in that country/region?
without any further information, you can try this:

YourModel.group('country').order('count_country DESC').limit(3).count('country')

When you call count on the field, rails The AS count_field_name field is automatically added to the query.

Count must be called at the end of the query because it returns an ordered hash.

In my In one of the models, I have a country column. How would I choose the top 3 countries/regions based on the number of models in that country/region?

Without any further information, you can try this:

YourModel.group('country' ).order('count_country DESC').limit(3).count('country')

When you call count on the field, rails will automatically add the AS count_field_name field to the query. p>

Count must be called at the end of the query because it returns an ordered hash.

WordPress database error: [Table 'yf99682.wp_s6mz6tyggq_comments' doesn't exist]
SELECT SQL_CALC_FOUND_ROWS wp_s6mz6tyggq_comments.comment_ID FROM wp_s6mz6tyggq_comments WHERE ( comment_approved = '1' ) AND comment_post_ID = 3298 ORDER BY wp_s6mz6tyggq_comments.comment_date_gmt ASC, wp_s6mz6tyggq_comments.comment_ID ASC

Leave a Comment

Your email address will not be published.