I have a query in MySQL designed with multi JOINs. But the sum total value is different if I use a Group or just one total value.
If I run the query like below I get e.b. 3 lines with the correct calculated price (price*tax_amount).
But if I don't use Group because I want just the overall total the result is different. I guess because the query use the average tax amount instead of the correct amount for each item.
Do you have any idea how I can fix this?
Table:
- contracts (contractID, some more data)
- objects (objectID, contractID, price, taxID)
- tax (taxID, tax_amount)
Query (works):
SELECT SUM(price*tax_amount) AS t_price
FROM contracts
JOIN objects
ON contracts.contractID = objects.contractID
JOIN tax
ON tax.taxID = objects.taxID
GROUP BY contracts.contractID
Result: 233.44 / 345.33 / 22.11
Query (Not work):
SELECT SUM(price*tax_amount) AS t_price
FROM contracts
JOIN objects
ON contracts.contractID = objects.contractID
JOIN tax
ON tax.taxID = objects.taxID
Result: 527.33