I am trying to get a table that adds all of the values gotten from the query my query on sql looks like this:
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;
this works perfectly on mysql, the problem is translating it to rails. I did something like this:
@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])
and on my views retrieve the values with the sum method:
<h2>Bancos</h2><hr>
<h4>Banamex</h4><%= @er.sum(:bmx) %>
<h4>BanBajio</h4><%= @er.sum(:bbjio) %>
<h4>Santander</h4><%= @er.sum(:santander) %>
Also tried with the loop <% @er.each do |t| %>
but didnt work either.
Any ideas here?
Thanks in advance!