-, CustomerState California,NewYork, First Normal Form.
, .
- 1
...
- 1
StateId: ( | NewYork |...)
...
- 1
...
ProductGiveAways.
PurchaseLimitDays
...
ProductGiveAways_State
ProductGiveAwaysId
StateId
...
_ - 1
...
-, , , :
// This is just an example, you have to change the 'California', 'New York' with their ids
SELECT * FROM Customer WHERE StateId IN ('California', 'New York')
, , :
// It not an accurate sql, just an example
SELECT Product.*
FROM Product
JOIN ProductGiveAways ON ProductId
JOIN ProductGiveAways_State ON ProductGiveAwaysId
WHERE ProductId NOT IN (
SELECT ProductId FROM Customer_Product JOIN ProductGiveAways ON ProductId
WHERE CustomerId =
AND ( TO_DAYS(now()) - TO_DAYS(PurchaseDate) ) < PurchaseLimitDays
)
AND StateId =
AND StartDate < now() < End Date // Elligible ProductGiveAways
source
share