我寫這個SQL:避免在SQL Server 2005中重複?
select distinct PayID, PaymentDate, AccountNumber, sum(PaymentAmount) as Amount
from tblInvoicePaymentDetails
where CustomerID = 'mud4978'
group by PayID, PaymentDate, AccountNumber
輸出是:
PayID PayDate Account Amount
1 2011-07-05 11:09:14.390 NULL 700.00
1 2011-07-05 11:09:14.407 NULL 100.00
2 2011-07-05 11:20:05.517 NULL 0.00
2 2011-07-05 11:20:05.547 9000 500.00
2 2011-07-05 11:20:07.000 9000 100.00
3 2011-07-05 12:19:22.017 100000 200.00
3 2011-07-05 12:19:22.077 100000 100.00
但我的要求是,以顯示3條記錄(避免重複)和量的總和是這樣的:
payid paydate account amount
1 2011-07-05 11:09:14 null 800.00
2 2011-07-05 11:20:05 9000 600.00
3 2011-07-05 12:19:22 100000 300.00
請幫忙
順便說一句,您已經提出了11個問題,並接受了零個答案。如果你回去接受幫助你的答案,那將是很有禮貌的。 –