组由“外部参考”组成SQL Server中的错误
我在下面的代码中使用一个简单的小组:
SELECT 'bcg-measles1' AS vaccgroup,
e0.providerid,
( SELECT count(DISTINCT e1.baseentityid) AS count
FROM bcgmeasles1 e1
WHERE e1.measles1_ = 'Vaccinated' AND e0.providerid = e1.providerid) AS numerator,
( SELECT count(DISTINCT e2.baseentityid) AS count
FROM bcgmeasles1 e2
WHERE e2.measles1_ <> 'Not Eligible' AND e0.providerid = e2.providerid) AS denominator
FROM bcgmeasles1 e0
GROUP BY 'bcg-measles1' , e0.providerid
我面临的错误说:
Each GROUP BY expression must contain at least one column that is not an outer reference.
我不明白为什么出现此错误,因为我只是在做一个简单的组。请帮忙!
I am using a simple group by statement in the code below:
SELECT 'bcg-measles1' AS vaccgroup,
e0.providerid,
( SELECT count(DISTINCT e1.baseentityid) AS count
FROM bcgmeasles1 e1
WHERE e1.measles1_ = 'Vaccinated' AND e0.providerid = e1.providerid) AS numerator,
( SELECT count(DISTINCT e2.baseentityid) AS count
FROM bcgmeasles1 e2
WHERE e2.measles1_ <> 'Not Eligible' AND e0.providerid = e2.providerid) AS denominator
FROM bcgmeasles1 e0
GROUP BY 'bcg-measles1' , e0.providerid
I am facing an error which says:
Each GROUP BY expression must contain at least one column that is not an outer reference.
I do not understand why this error is showing up, as I am only doing a simple group by. Please help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
错误消息是
您有
'bcg-measles1',这只是一个恒定的字符串字面。
删除该问题以解决问题(如@Charlieface所述)。
但是无论如何,产生这些结果的一种更简单的方法是使用以下
The error message is
You have
This contains an expression 'bcg-measles1' that is just a constant string literal.
Remove that to resolve the issue (as noted by @Charlieface).
But in any event a simpler way of producing these results would be to use the below