Assume a query of the following form
operatingExpenses = Expense.find(:all,
{:select=>\"categories.activityType, categories.name heading, sum(amount
Just do find_by_sql
and apply the SUM
on a decimal column :
operating_expenses = Expense.find_by_sql ['SELECT cat.activityType, cat.name heading, SUM(exp.amount) AS amount FROM expenses exp JOIN expense_categories cat ON exp.category_id = cat.id GROUP BY cat.id, cat.activityType, cat.name, exp.id ORDER BY cat.activityType, amount DESC']
Under the 'amount' column of operating_expenses you'll got your total automatically converted to decimal.
N.B. : cat.id and exp.id are required to respect SQL standard.