如果要使用以下查询针对该报告存在特定列,我正在尝试获取有关详细信息以及状态的查询。
select rh.Rec_ID
,rh.Report_ID
,rh.Report_Name
,rh.Source_Type_Display
,rh.Description
,rh.IndID
,rh.Name
,rh.Time_Updated
,count(*) OVER() as TotalCount
,case when count(rd.demo) > 0 THEN 'Completed' ELSE 'incomplete' END
FROM v_Report_Header_OV rh
inner join v_Table_NI_Report_Demo rd
ON rh.Report_ID = rd.Report_ID
WHERE rh.Client_ID = 12324
我遇到错误
Column 'v_Report_Header_OV.Rec_ID' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.
我不确定为什么会出错,请问有人可以帮忙
非常感谢。
答案 0 :(得分:3)
您错过了group by
select rh.Rec_ID
,rh.Report_ID
,rh.Report_Name
,rh.Source_Type_Display
,rh.Description
,rh.IndID
,rh.Name
,rh.Time_Updated
,count(*) OVER() as TotalCount
,case when count(rd.demo) > 0 THEN 'Completed' ELSE 'incomplete' END
FROM v_Report_Header_OV rh
inner join v_Table_NI_Report_Demo rd
ON rh.Report_ID = rd.Report_ID
WHERE rh.Client_ID = 12324
group by rh.Rec_ID
,rh.Report_ID
,rh.Report_Name
,rh.Source_Type_Display
,rh.Description
,rh.IndID
,rh.Name
,rh.Time_Updated