title: SQL SUM columns from different tables
body: <p>Good Afternoon, </p>
  
  <p>I currently have the query:</p>
  
  <pre><code>SELECT erp_user.login, 
  SUM(invoice_header.invoice_amount) as 'Invoices Billed'
  FROM erp_user
  LEFT JOIN order_header ON erp_user.erp_user_id = order_header.req_by
  LEFT JOIN invoice_instruct_header ON order_header.order_id = invoice_instruct_header.order_id
  LEFT JOIN invoice_header ON invoice_instruct_header.instruct_id = invoice_header.instruct_no
  WHERE erp_user.supervisor_id IS NOT NULL AND user_id_type = 'I' AND erp_user.company_id IS NOT NULL  AND erp_user.is_active = 1 
  GROUP BY erp_user.login
  </code></pre>
  
  <p>It gives me a list of total billing in our system by employee where the employee is signed to a job on the job header. </p>
  
  <p>I would love to add the total amount of open PO's to this query so I added:</p>
  
  <pre><code>SELECT erp_user.login, SUM(invoice_header.invoice_amount) as 'Invoices Billed', sum(po_header.po_amount) AS "Open PO's"
  FROM erp_user
  LEFT JOIN order_header ON erp_user.erp_user_id = order_header.req_by
  LEFT JOIN invoice_instruct_header ON order_header.order_id = invoice_instruct_header.order_id
  LEFT JOIN invoice_header ON invoice_instruct_header.instruct_id = invoice_header.instruct_no
  LEFT JOIN po_header ON order_header.order_id = po_header.order_id
  WHERE erp_user.supervisor_id IS NOT NULL AND user_id_type = 'I' AND erp_user.company_id IS NOT NULL  AND erp_user.is_active = 1  AND po_header.status = 1
  GROUP BY erp_user.login
  ORDER BY "Open PO's"
  </code></pre>
  
  <p>That query gives me numbers in my Open PO's column, but they are incorrect and I'm at the point now where I can't figure out how to troubleshoot this. </p>
  
  <p>Can someone please point me in the right direction? I don't mind doing the work, just need a pointer. Thanks!</p>