tonydismukes
Programmer
I have a table holding information on data sent:
I need to generate a report showing the total quantity of data sent or received by a particular account, within a date range, broken down by trading partner (the party that this account is either sending to or receiving from).
I can get the data I need with this query:
The problem is that this gives me 2 rows for each partner - 1 for data sent and 1 for data received, i.e.
Partner totalData
11 80
11 60
14 100
14 130
etc
What I want is to group the totals by Partner, i.e.
Partner totalData
11 140
14 230
etc
How do I accomplish this?
Thanks in advance for any help!
Code:
CREATE TABLE DataSent
(SENDERKEY int,
RECEIVERKEY int,
SIZE int,
PROCESSDATE datetime,
... other irrelevant fields ...)
I can get the data I need with this query:
Code:
select receiverkey as partner, sum(size)as totalData from DataSent where senderkey = 42
and (processed between '1/1/2006 00:00:01 AM' and '1/31/2006 11:59:59 PM')
group by receiverkey
union
select senderkey as partner, sum(size)as totalData from DataSent where receiverkey = 42
and (processed between '1/1/2006 00:00:01 AM' and '1/31/2006 11:59:59 PM')
group by senderkey
The problem is that this gives me 2 rows for each partner - 1 for data sent and 1 for data received, i.e.
Partner totalData
11 80
11 60
14 100
14 130
etc
What I want is to group the totals by Partner, i.e.
Partner totalData
11 140
14 230
etc
How do I accomplish this?
Thanks in advance for any help!