2016-08-18 76 views
0
SELECT fp.Physician_Key, 
     fp.Month, 
     pd.DisplayName, 
     hd.ProductName, 
     SUM(AmtPaid) AS TotalCost 
FROM F_ProgramCost_Fact fp 
INNER JOIN D_HEALTHPLANDim hd ON hd.HealthPlan_Key = fp.HealthPlan_Key 
INNER JOIN D_PHYSICIANDim pd ON fp.Physician_Key = fp.Physician_Key 
INNER JOIN F_MemberPatient_FactLess mpf ON fp.MemberPatientFact_Key = mpf.MemberPatientFact_Key 
GROUP BY fp.Physician_Key 

獲取此錯誤「列'F_ProgramCost_Fact.Month'在選擇列表中無效,因爲它不包含在聚合函數或GROUP BY子句中。以下SQL代碼將引發錯誤

請幫忙! 感謝

+0

當你'SUM'ming,你怎麼指望SQL引擎爲'F_ProgramCost_Fact.Month'列hangle不同的價值觀? 那麼其他專欄呢? 您必須將它們添加到「GROUP BY」,以便您可以通過其他列的每個組合獲得「SUM」。 – PauloASilva

回答

0

你需要按所有列:

select fp.Physician_Key,fp.Month,pd.DisplayName,hd.ProductName,SUM(AmtPaid) as TotalCost 
From F_ProgramCost_Fact fp 
Inner Join D_HEALTHPLANDim hd 
ON hd.HealthPlan_Key = fp.HealthPlan_Key 
Inner join D_PHYSICIANDim pd 
ON fp.Physician_Key = fp.Physician_Key 
Inner Join F_MemberPatient_FactLess mpf ON fp.MemberPatientFact_Key = mpf.MemberPatientFact_Key 
Group By fp.Physician_Key,fp.Month,pd.DisplayName,hd.ProductName 
+0

感謝您的幫助! –

相關問題