Created
February 27, 2018 14:58
-
-
Save antico5/098518fc9879a5f4aabb034997f9cc1d to your computer and use it in GitHub Desktop.
Select count having
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
User.select('sales_person_id, COUNT(1) as us_count').group(:sales_person_id).having('COUNT(1) > 1') | |
class ApplicationRecord | |
def self.group_having(field, count) | |
select("#{field}, COUNT(1) as count").group(field).having("COUNT(1) > #{count}") | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment