I have a CRMOffer table containing customerID and other CRMOffer data. And a Sell table containing customerID and sellValue and sellPK.
Sell table has a explicit PK, CRMOffer sadly doesn't have one available.
I must join these tables, so that I can relate CRM offers to actual sells.
If Sell table doesn't have a specific customerID, sell value will be null. But if it does, and there are multiple CRM offers to the same customer ID, the join will result in duplicated SellPK and sellValue.
I must then group by CRMOffer's customerID and sum sell values, but sum only once for each SellPK.
A given sell event may be duplicated, in case CRM made multiple offers to a customer that generated a sell. But there may also be multiple distinct sells from the same customer.
Sorry I think the explanation is kinda confusing. Basically I must sum values of distinct sells being careful to exclude duplications resulted to multiple CRM offers. I can see if a sell is duplicated by its SellPK. I can use
count(DISTINCT customerID) to remove duplications from customerID, but I can't find a way to remove duplications from sell value.