Help creating a single SELECT statement for SQL Reports
I am trying to create an payment report which lists the sum in each account. The table is in SQL SERVER 2005 and it has the following table
[Account] [Amount] [Type]
1111 10 C
1111 10 C
1111 15 D
1111 5 D
1112 10 C
1112 15 C
1112 10 D
1112 10 D
I need to create report that will sum the Credit and Debit for each account Ou开发者_StackOverflowtput
1111 0
1112 5
Is there a single SELECT statement that I can use to generate the output? I can do this by creating temp tables but I was wondering if I can do it in a single SELECT statement
select Account,
sum(case when Type='D' then Amount * -1 else Amount end) as AmountSum
from Payment
group by Account
精彩评论