Counting and grouping at the same time

后端 未结 4 1997
轻奢々
轻奢々 2020-12-08 01:39

I have a Mail model with the following schema:

t.string   \"mail\"
t.integer  \"country\"
t.boolean  \"validated\"
t.datetime \"created_at\"
t.d         


        
4条回答
  •  再見小時候
    2020-12-08 02:09

    I too had to group data with city name and showing count of how many rows are there for each city with specific condition. So this is how I did:

    CityData.where(:status => 1).group(:city_name).count
    

    Output of this was:

    {:Mumbai => 10, :Dublin => 7, :SF => 9}
    

提交回复
热议问题