I’m trying to get the sum of 3 database fields.
Instead of calling find, I’m using sum like this:
@itemsum = Order.sum(:item_total) @shipsum = Order.sum(:shipping_total) @taxsum = Order.sum(:tax_total)
But, would rather not make 3 database calls to do so.
I can’t find any documentation on sum as a finder, so was wondering if
anyone has a solution for getting the sum of multiple collumns this way.
The end sql result I’m trying to achieve is:
SELECT sum(tax_total) AS sum_tax_total, sum(item_total) AS
sum_item_total, sum(shipping_total) AS sum_shipping_total FROM orders
Of course I could just do a find_by_sql, but was just trying something