I want to sum all elements (e.g. price) from table column where some values (type) equal to some param (1):
Table
id type price
-------------
1 1 10
2 1 8
3 2 7
4 1 2
I think, it may be like this:
Table.where(:type => 1). ???
I need to get 20.
Table.where(:type => 1).sum(:price)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With