Considering you have a table that maintains the group and primary customer relationship within that group, you can execute the below mentioned query to get the desired results.
CUSTMOER_GROUP should look something like this;
CUSTOMER_ID, CUSTOMER_ID_P
C1, C1
C2, C1
C3, C1
(The first column contains the list of customer ids, and the second column mentions the primary customer id for those customers thus making the groups automatically)
UPDATE TBLA
FROM CUSTOMER_TEST TBLA, CUSTOMER_TEST TBLB, (SELECT * FROM CUSTOMER_GROUP WHERE CUSTOMER_ID_P IN (SELECT DISTINCT CUSTOMER_ID_P FROM CUSTOMER_GROUP where customer_id = customer_id_p)) TBLC
SET CAL_QTY = CASE WHEN TBLC.CUSTOMER_ID IS NOT NULL THEN TBLB.QTY ELSE TBLB.CAL_QTY END
WHERE TBLA.CUSTOMER_ID = TBLB.CUSTOMER_ID
AND TBLA.CUSTOMER_ID = TBLC.CUSTOMER_ID
AND TBLA.PRODUCT = TBLB.PRODUCT
AND TBLA.DATE_ = TBLB.DATE_;
Hope it helps...
Considering you have a table that maintains the group and primary customer relationship within that group, you can execute the below mentioned query to get the desired results.
CUSTMOER_GROUP should look something like this;
CUSTOMER_ID, CUSTOMER_ID_P
C1, C1
C2, C1
C3, C1
(The first column contains the list of customer ids, and the second column mentions the primary customer id for those customers thus making the groups automatically)
Hope it helps...