J'ai 3 tables:
Customer (CustomerID) CustomerEvent (CustomerEventID, CustomerID, EventTypeID) EventType (EventTypeID)
Certains loggings Customer ont certains loggings CustomerEvent avec un EventType, certains loggings Customer n'ont pas d'loggings CustomerEvent.
Comment identifier / insert les loggings CustomerEvent manquants de chaque EventType pour chaque logging client?
Mon numéro actuel est un peu plus détaillé que cela, cependant, c'est la pièce avec laquelle je me bats.
Puis-je utiliser une instruction select pour identifier tous les loggings CustomerEvent manquants? Ou devrais-je besoin d'UNION sur chaque logging EventType?
Utilisation de cross join
pour générer un set de tous CustomerId, EventTypeId
et filtrant ceux qui existent dans CustomerEvent
avec not exists()
select c.CustomerId, e.EventTypeId from Customer c cross join EventType e where not exists ( select 1 from CustomerEvent ce where c.CustomerId = ce.CustomerId and e.EventTypeId = ce.EventTypeId )
select * from CUSTOMEREVENT CE left join CUSTOMER C ON C.CustomerID = CE.CustomerID left join EVENTTYPE ET ON CE.EventTypeID = ET.EventTypeID where C.CustomerID IS NULL OR ET.EventTypeID IS NULL