Multiple sum method in one query rails
<p>I am trying to get a table that adds all of the values gotten from the query my query on sql looks like this: </p>

<pre><code>SELECT sum(bmx), sum(amex), sum(bbjio), sum(bancomer), sum(santander), sum(pesos), sum(dolares), sum(gastos),sum(venta_tot) 
FROM avm.avs
WHERE usuario_id = 2;
</code></pre>

<p>this works perfectly on mysql, the problem is translating it to rails. I did something like this: </p>

<pre><code>@er = Av.find_by_sql(["SELECT * FROM avm.avs where created_at between ? and ? and usuario_id in(select id from avm.usuarios where tienda = ?)",@startd, @endd, @nom])
</code></pre>

<p>and on my views retrieve the values with the sum method:</p>

<pre><code>&lt;h2&gt;Bancos&lt;/h2&gt;&lt;hr&gt;
        &lt;h4&gt;Banamex&lt;/h4&gt;&lt;%= @er.sum(:bmx) %&gt;
        &lt;h4&gt;BanBajio&lt;/h4&gt;&lt;%= @er.sum(:bbjio) %&gt;
        &lt;h4&gt;Santander&lt;/h4&gt;&lt;%= @er.sum(:santander) %&gt;
</code></pre>

<p>Also tried with the loop <code>&lt;% @er.each do |t| %&gt;</code> but didnt work either.</p>

<p>Any ideas here? </p>

<p>Thanks in advance!</p>