Group, count, having, and order by in Rails
Try something like:
Person.select("id, age").group(:id, :age).having("count(id) > 1").order("age desc")
Person.select('COUNT(1) as people_count').order('age DESC').group(:age).having('people_count > 1')
I find the other answers didn't work for me. I had to do something like this
Person.group(:age).having('count(*) > 1').order('age desc').count