我引用了这个和其他堆栈
这是我所做的:
SELECT
ReportDate,
ReportID = STUFF((SELECT ',' + CAST(t1.ReportID AS varchar(50))
FROM BackEndEfficiency t1
WHERE t1.ReportID = t2.ReportID
FOR XML PATH ('')), 1, 1, '')
FROM
BackEndEfficiency t2
GROUP BY
ReportDate
错误:
选择列表中的“ BackEndEfficiency.ReportID”列无效,因为它既不包含在聚合函数中,也不包含在GROUP BY子句中。
我为什么要按此ReportDate
分组,为什么会收到此错误?
数据结构示例
ReportDate ReportID
--------------------
2020-03-11 30
2020-03-11 31
2020-03-16 32
2020-03-16 33
我想得到以下输出:
ReportDate ReportID
--------------------
2020-03-11 30,31
2020-03-16 32,33
我认为您想要ReportDate
相关子句。我建议:
select bee.ReportDate,
stuff((select ',' + CAST(t1.ReportID as varchar(50))
from BackEndEfficiency bee2
where bee2.ReportDate = bee.ReportDate
for xml path ('')
), 1, 1, '')
from (select bee.ReportDate
from BackEndEfficiency bee
) bee;
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句