Let’s say I have two tables with identical structure, call them A & B. The only columns of concern for this issue are product_type, price, and volume.
Each combination of product_type & price may be repeated multiple times in each table with varying volumes. I’m trying to find instances of a combination having a different TOTAL volume in one table than the other.
This would include when a combination from table A is not represented in Table B whatsoever, or vice-versa.
===================
Example:
Table A:
ID Product_type Price Volume
--- ------------ ----- ------
1 X $1 10
2 X $1 11
3 Z $2 10
Table B:
ID Product_type Price Volume
-- ------------- ----- -------
1 X $1 21
2 Y $1 5
3 Z $2 7
4 Z $2 4
Notice that sum of volumes of X @ $1 in Table A is 21, which matches Table B.
Y @ $1 is present in Table B, but not in A.
Z @ $2 is present in both tables but the sums of their volumes differ. I would like the query to return each product_type and price combination that breaks the rules (i.e. Y @ $1 and Z @ $2).
I’ve tried using GROUP, UNION, DISTINCT, sub-queries and various combinations of the above but can’t seem to figure it out.
1 Answer