我的问题与 ServiceASpecificField
和 ServiceBSpecificField
有关。我觉得这两个字段放置不当,因为对于 SubscriberServiceMap
表中所有订阅者的 service A
的所有记录,ServiceBSpecificField
将具有 null 值,并且反之亦然。
如果我在订阅者表中移动这两个字段,那么我将遇到另一个问题。所有仅使用服务 A
的订阅者的 Subscribers.ServiceBSpecificField
中的值将为空。
那么理想情况下应该怎么做呢?
最佳答案
在 Service_A 和 _B
表上放置检查约束,例如:
alter table Service_A add constraint chk_A check (ServiceID = 1);
alter table Service_B add constraint chk_B check (ServiceID = 2);
然后你就可以加入了
select *
from SubscriberService as x
left join Service_A as a on (a.SubscriberID = x.SubscriberID and a.ServiceID = x.ServiceID)
left join Service_B as b on (b.SubscriberID = x.SubscriberID and b.ServiceID = x.ServiceID)
关于database - 如何处理可选列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4516290/