Sum of a multiplication of two columns grouped by another column in an inner join of three tables returns wrong value. Below are my three tables:
Table2:
Table3:
My Query is as below:
SELECT c.price, c.quantity, SUM( c.quantity * c.price ) AS price,
group_concat( a.rate
SEPARATOR '<br>' ) AS rates, c.hsn AS hsn
FROM tax_wa a
INNER JOIN tax_rate_class b ON a.tax_rate_id = b.tax_rate_id
INNER JOIN inv_item c ON b.tax_class_id = c.tax_class_id
WHERE c.invoice_id = '17'
GROUP BY c.hsn
And the result is:
But above one is not correct... To expain it, if you run the below query on the inv_item table (alone, with no joins) you get correct results:
SELECT price, quantity, sum( quantity * price )
FROM `inv_item`
WHERE invoice_id = '17'
GROUP BY hsn
Result is good:
Above result the wrong value calculated if you add all