您需要一个包含所有组合的驱动程序表来连接您拥有的数据:
select allcombos.subscriptionId, allcombos.ProductPermissionId,
sp.granted
from (select SubscriptionId, ProductPermissionId
from subscription s cross join ProductPermission pp
) allcombos left outer join
SubscriptoinPermission sp
on sp.subscriptionId = allcombos.subscriptionId and
sp.ProductionPermissionId = allcombos.ProductPermissionId
您可以添加一个where
子句来指定订阅 ID,但您需要在其前面加上 allcombos:
where allcombos.SubscriptionId = <whatever>
如果您只希望它用于订阅产品,则更改 allcombos 子查询:
select allcombos.subscriptionId, allcombos.ProductPermissionId,
sp.granted
from (select distinct SubscriptionId, pp2.ProductPermission
from subscriptionProduct sp join
ProductPermission pp
on sp.ProductPermissionId = pp.ProductPermissionId left outer join
ProductionPermission pp2
on pp.ProductId = pp2.ProductId
) allcombos left outer join
SubscriptionPermission sp
on sp.subscriptionId = allcombos.subscriptionId and
sp.ProductionPermissionId = allcombos.ProductPermissionId
这可能不是获得订阅中产品的所有权限的最干净的更改。如果您有一个 SubscriptionProduct 表,那就太好了。但是,这样的事情应该有效。