I have a table which stores a category mix for customers. The number of categories may change, but the breakdown must always be less than or equal to 100% for each customer.
custom type_ pct
------- ------- -----
Cust1 Type A .33
Cust1 Type B .17
Cust1 Type C .50
Cust2 Type A .30
Cust2 Type D .10
Cust2 Type E .10
Cust2 Type F .50
Any ideas on how I can add a check constraint to enforce this rule?
Here's my start...
ALTER TABLE cust_mix ADD CONSTRAINT ttl_pct_mix CHECK (SUM (pct) <= 1);
But this checks all rows, regardless of the customer ID