我的查询
select distinct
EnglishProductCategoryName,
sum(isnull(fic.SalesAmount,0))InternetSalesAmount,
sum(isnull(frs.SalesAmount,0))ResellerSalesAmount
from dimproduct dp join DimProductSubcategory dps on dp.ProductSubcategoryKey=dps.ProductSubcategoryKey
join DimProductCategory dpc on dpc.ProductCategoryKey=dps.ProductCategoryKey
left join FactInternetSales fic on fic.ProductKey=dp.ProductKey
left join FactResellerSales frs on frs.ProductKey= dp.ProductKey
group by EnglishProductCategoryName
但是当我这样做
select sum(isnull(fis.SalesAmount,0))InternetSalesAmount from FactInternetSales
select sum(isnull(frs.SalesAmount,0))resellerSalesAmount from FactResellerSales
比较整个英文产品类别名称的总和与互联网销售额的总和,代理商的销售额应该相同但不相同
将寻求帮助 谢谢
答案 0 :(得分:0)
检查是否缺少ProductSubcategory或ProductCategory
select distinct
EnglishProductCategoryName,
sum(isnull(fic.SalesAmount,0))InternetSalesAmount,
sum(isnull(frs.SalesAmount,0))ResellerSalesAmount
from dimproduct dp left join DimProductSubcategory dps on dp.ProductSubcategoryKey=dps.ProductSubcategoryKey
left join DimProductCategory dpc on dpc.ProductCategoryKey=dps.ProductCategoryKey
left join FactInternetSales fic on fic.ProductKey=dp.ProductKey
left join FactResellerSales frs on frs.ProductKey= dp.ProductKey
group by EnglishProductCategoryName