sum over multiple tables [message #444410] |
Sun, 21 February 2010 14:21  |
nsnvc
Messages: 3 Registered: February 2010
|
Junior Member |
|
|
I'm trying to do a sum over 2 different tables but can't get it to work...
This is the idea:
I have a table A with client ID, time-id (per day), purchase amount and segment code.
In another table (let call it B) I have a lot of client ID's and also their purchase amount, time-id and segment code. I want to sum the purchase amount for every client from table A and B for clients with certain segment code from table B.
This is what I have now:
select client_id, purchase_amountA+ purchase_amountB from tableA, tableB where
A.client_id = B.client_id
and time_id between 20090101 and 20091001
and B.segment_code = 'A'
This does the job, but it selects only client_id's which are in both tables. I want to select all client_id from table B with segment_code 'A' and add the purchase_amount from table A to their purchase amount from table B, at least, if they have any purchase amount in table A.
Any help is welcome!
|
|
|
|
|
|
|