Sum and Group by in Rails

前端 未结 1 787
孤独总比滥情好
孤独总比滥情好 2021-01-06 16:56

I have a table defined as such:

Name - Order# - Widget Count
Bob  - 12311  - 6
Nancy- 12555  - 8
BoB  - 87573  - 12
Nancy- 12929  - 4

I\'d

相关标签:
1条回答
  • 2021-01-06 17:23

    This should work, assuming your model is called Person:

    Person.group(:name).count(:widget_count)
    

    You can find more info about it on RailsGuides for ActiveRecord.

    0 讨论(0)
提交回复
热议问题