DRD
DRD

Reputation: 131

Rails 4 activerecord group

I have an Order table and each order has a SOURCE and ORDER TOTAL. The source is basically were the order came from (Phone, Web, Ebay and so on).

I would like you get all orders and display them grouped by SOURCE and show the Total amount for each SOURCE.

Upvotes: 3

Views: 59

Answers (1)

cristian
cristian

Reputation: 8744

Order.group(:source).sum(:order_total)

More about sum and group

Upvotes: 1

Related Questions