我正在建立多对多关系。下面的详细信息,当我尝试通过ShippingCompanyId求和时,我得到相同的金额,该如何解决?我们有一个非常复杂的数据集市,并且有许多类似的场景。
我试图改变多对多关系,等等
样本值:
create table dbo.DimCustomer
(
DimCustomerId int,
PersonName varchar(255)
)
insert into dbo.DimCustomer
values
('1','Joe'),
('2', 'Sally')
create table dbo.DimShippingCompany
(
DimShippingCompanyid int,
ShippingName varchar(255)
)
insert into dbo.DimShippingCompany
values
('1','UPS'),
('2', 'Fedex')
create table dbo.FactShipment
(
FactShipmentId int primary key,
DimCustomerId int,
DimShippingCompany int,
ShipmentQuantity int,
ShipmentTotal numeric(10,2)
)
insert into dbo.FactShipment
values
(1,1,1,5,8),
(2,1,1,7,12),
(3,1,2,5,9),
(4,2,1,3,4),
(5,2,2,5,7)
create table dbo.FactOrder
(
FactOrderId int primary key identity(1,1),
DimCustomerId int,
OrderAmount numeric(10,2)
)
insert into dbo.FactOrder
values
(1,50),
(1,28),
(2,41)