如何获得按天分组的金额总和 [英] How do i get sum of amount group by Day
本文介绍了如何获得按天分组的金额总和的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有桌子
具有以下字段的虚拟对象
I have table
Dummy with following fields
Day int
Name varchar(50)
Amount int
此处名称仅包含A或B
我想要这样的结果
here Name Takes only A or B
i want result like this
Day A B
1 100 50
2 35 26
我想要每天A和B的数量.用户可以在一天之内没有任何记录
感谢任何帮助
i want some of amount For A and B for each Day. User Can have any no of records for one day
Any help is appreciated
推荐答案
select sum(A+B) as OneDay from Days
Group by Day
之前 :
Here is the solution :
select * from (select [DAY],name, amount from Dummy) upt
pivot
(
sum(amount)
for name in ([A], [B])
) as p
PIVOT
文档:
http://msdn.microsoft.com/en-us/library/ms177410.aspx [ ^ ]
希望对您有所帮助.
PIVOT
documentation :
http://msdn.microsoft.com/en-us/library/ms177410.aspx[^]
Hope it helps.
这篇关于如何获得按天分组的金额总和的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文