title: sql not calculating sum correctly
body: <p>I've got the following sql query, it seems to be returning data, but the sum of the invoice_total (4th column) is not calculating properly. At the moment although I have about 50 records in purchase files with the duplicate supplierID, I currently only have 4 individual supplier records filled with the invoice_total. The returned result is not what I have put in.</p>
  
  <pre><code>SELECT p.orderID, s.supplier, SUM(IFNULL(pl.line_price,0)) AS total_order, SUM(IFNULL(p.invoice_total,0)) AS invoice_total  
    FROM purchase p 
    LEFT JOIN purchase_line pl 
    ON p.orderID = pl.orderID 
    LEFT JOIN supplier s 
    ON p.supplierID = s.supplierID 
    WHERE (p.date BETWEEN '2015-01-01' AND '2015-12-30')
    GROUP BY p.supplierID 
    ORDER BY p.supplierID ASC
  </code></pre>
  
  <p>Table definitions are as follows along with sample data
  purchase</p>
  
  <pre><code>  orderID, date, supplierID, supplier_ref, invoice_total
    001, 2015-11-15, 1, abc, 11300000 
    002, 2015-11-15, 2, def, 23900000
    003, 2015-11-15, 3, ghi, 68265000
    004, 2015-11-15, 4, jkl, 31300000
    005, 2015-11-15, 5, lmn, [Null]
  
    purchase_line
    orderID, item_price, qty, line_price
    001,100000,50000, (that would be line_price*qty)
    001,200000,25000,
    001,300000,10000,
    002,400000,20000,
    003,300000,30000,
    004,200000,20000,
  
    supplier
    supplierID, supplier, address1, address2, zip
    1, Apple 
    2, Microsoft,
    3, Oracle
    4, SAP
    5, IBM
  </code></pre>
  
  <p>The data that seems to be returned for the total_invoice field is. Bear in mind I have only populated one row of data with the invoice_total filled in. However I have lots of records with Null in that field which are associated to supplier 1 or supplier 2.</p>
  
  <pre><code>  supplierID, invoice_total
    1, 700600000
    2, 95600000
    3, 136530000
  </code></pre>