title: Rails 5 Multiple Sums and Join
body: <p>This question is related to <a href="https://stackoverflow.com/questions/40144422/rails-5-sum-and-group">this</a> previously asked question.</p>
  
  <p>My DB columns for model Taxline: ID, RECEIPT, TAXID, BASE, AMOUNT
  With entries:
  1,1,001,30$,3$</p>
  
  <p>2,1,001,50$,5$</p>
  
  <p>3,2,001,20$,2$</p>
  
  <p>And then a second table with columns: TICKETID, TICKETNUMBER</p>
  
  <p>My controller</p>
  
  <pre><code>class TaxlinesController &lt; ApplicationController
  
    def index
      @taxlines = Taxline.group(:RECEIPT).sum(:AMOUNT)
    end
  
  end
  </code></pre>
  
  <p>My view</p>
  
  <pre><code> &lt;% @taxlines.each do |receipt, amount| %&gt;
  
          &lt;td&gt;&lt;%= receipt %&gt;&lt;/td&gt;
          &lt;td&gt;&lt;%= amount %&gt;&lt;/td&gt;
   &lt;% end %&gt;
  </code></pre>
  
  <p>This works great to show a ticket for each row with corresponding total amount.</p>
  
  <p><strong>Question 1</strong>. What is the proper way to also show in view sum of BASE? I tried <code>.sum(:AMOUNT, :BASE) and .sum(:AMOUNT).sum(:BASE)</code> but they both don't work.</p>
  
  <p><strong>Question 2</strong>. If now I call in view for instance <code>&lt;%= taxline.TAXID %&gt;</code> I get an error. 
  To solve this I tried to add in view <code>&lt;% @taxlines.each do |receipt, amount, taxid| %&gt; and &lt;td&gt;&lt;%= taxid %&gt;&lt;/td&gt;. And in controller  @taxlines = Taxline.group(:RECEIPT).sum(:AMOUNT).select(:TAXID)</code>. But it shows a blank column.</p>
  
  <p><strong>Question 3</strong>. I want to show TICKETNAME value from TICKETS table.I have already set in Ticketline Model <code>belongs_to :ticket</code>. I assume that after solving question 1 I will be able to do ticketline.ticket.TICKETNAME.Right?</p>