
Originally Posted by
Ajax
Ah - it is because you have 3 sales records and 2 SOH records - so SOH is repeated 3 times - and added 3 times.
You could try changing sum to avg or to be clearer you need two group by queries, one on the Sales table and one of the SOH table which you then combine in a third query, linking on product.
However it does get more complicated because you might have sales in the year, but no SOH (e.g. a new product), or you might have a SOH, but no sales. In either of these cases, a result will not appear.
To resolve this you need to bring in the product table as well and left join it to the two group by queries - so you will see all products and a SOH where it exists and sales where they exist