问题描述
我使用的是 Microsoft SQL Svr Mgmt Studio 2008.我无权创建临时表(公司限制创建或修改表的能力),或者我会用它来解决这个问题.
I'm using Microsoft SQL Svr Mgmt Studio 2008. I don't have access to create a temporary table (company restricts ability to create or modify tables) or I would use that to solve this problem.
我已经成功地使用联合查询来组合三个选择查询的结果.现在我试图总结联合的结果.
I have successfully used a union query to combine the results of three select queries. Now I am trying to sum the results of the union.
当我执行下面的查询时,我收到:
When I execute the query below I receive:
然后当我通过我删除组时:
And then when I remove the group by I get:
这是我目前的查询:
对于之前的任何问题,我都无法找到解决方案.
I haven't been able to find a solution to this on any of the previous questions.
推荐答案
你需要给你的派生表取别名,你还必须使用一个带有 have 子句的 group by.
You need to alias your derived table, you must also use a group by with a having clause.
这篇关于对联合查询求和的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!