SQL Server:合并同一行中的两个值
我有以下联合所有结果,
ID Name Date Team Total#1 Total#2
1 Test_1 4/25/2011 Team_1 110 0
1 Test_1 4/25/2011 Team_2 20 0
1 Test_1 4/25/2011 Team_3 170 0
1 Test_1 4/25/2011 Team_1 0 151
1 Test_1 4/25/2011 Team_3 0 98
我希望将每个团队的结果合并起来。有一些重复的球队名称具有不同的总价值,并且有一些独特的球队名称只有一个总价值。
ID Name Date Team Total#1 Total#2
1 Test_1 4/25/2011 Team_1 110 151
1 Test_1 4/25/2011 Team_2 20 0
1 Test_1 4/25/2011 Team_3 170 98
有什么想法吗?
I have the following union all results
ID Name Date Team Total#1 Total#2
1 Test_1 4/25/2011 Team_1 110 0
1 Test_1 4/25/2011 Team_2 20 0
1 Test_1 4/25/2011 Team_3 170 0
1 Test_1 4/25/2011 Team_1 0 151
1 Test_1 4/25/2011 Team_3 0 98
I am looking to combine the results for each team. There are some duplicate team names with different totals and there are some unique teams names with only one total value.
ID Name Date Team Total#1 Total#2
1 Test_1 4/25/2011 Team_1 110 151
1 Test_1 4/25/2011 Team_2 20 0
1 Test_1 4/25/2011 Team_3 170 98
Any thoughts?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
只需使用聚合函数和
GROUP BY
:Just use aggregate functions and
GROUP BY
:这行不通?
doesn't this work?
将
select... union select...
设为子查询,“外部”查询针对它发出一个 group by 。Make the
select... union select...
a subquery, and the "outer" query issues a group by against it.假设由于某种原因标准分组不适合您可以这样做
您也可以对 CTE 执行相同的操作
或联合上的分组将起作用
Assuming for some reason standard Grouping isn't working for you could do this
You could also do the same with CTE's
OR grouping on the union would work to