I can use the following :
User.where(\"zip_code = \'48104\'\").group(\'users.id\').count
To get hashes like :
{195=>1, 1
As said before by orourkedd the accepted answer is not great when dealing with a large amount of records. I too recently encountered this issue and have large tables that I definitely don't want to load into memory. So here is what works for me.
users=User.where("zip_code = '48104'").group('users.id')
user_count=User.where(id: users.select(:id)).count
Rails will handle the users.select part like a subquery. This works with Rails 4