I need to get a list of places ordered by the number of images that I have in the DB for these locations, here is my query
Location.select(:city).group(:city).order("SUM(images_count) DESC").sum(:images_count)
It worked like a charm, unfortunately, now I need to add a province and a country to prevent ambiguities, so now I have this
Location.select(:city, :province, :country).group(:city, :province, :country).order("SUM(images_count) DESC").sum(:images_count)
And this does not work :(
Can someone help me with this request?
source share