以下SQL代码引发错误

时间:2016-08-18 08:44:58

标签: sql join group-by

{{1}}

获取此错误“列'F_ProgramCost_Fact.Month'在选择列表中无效,因为它不包含在聚合函数或GROUP BY子句中。”

请帮忙! 感谢

1 个答案:

答案 0 :(得分: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