[英]Inner join with count in select query
I am trying to get the query for details along with the status if the particular column exists for that report using the below query. 我正在尝试使用以下查询来获取有关详细信息以及状态的查询,如果该报告存在特定的列。
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
I am getting below error 我低于错误
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.
I am not sure why i am getting error, Could any one please help on this 我不确定为什么会出错,请问有人可以帮忙吗
Many thanks in advance. 提前谢谢了。
you missed group by
您错过了
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.