Lets say I have a table called TRANSACTIONS with the following columns:
[tt]
customer item quantity total_cost
-------- ---- -------- ----------
Bob 121 4 400.00
Mary 115 1 50.00
John 100 2 100.00
Mike 121 7 [NULL]
[/tt]
I want to select all the records from the table however, for Mike instead of displaying NULL for the total cost I need the query to somehow CALCULATE the total_cost by finding another customer who bought the item and then dividing their total_cost by their quantity and then multiplying it by the quantity for the customer who is missing the value.
So for Mike you would have 400.00 (Bob's total) / 4 (Bob's quantity) * 7 (Mike's quantity) = 700.00 and the results would look like:
[tt]
customer item quantity total_cost
-------- ---- -------- ----------
Bob 121 4 400.00
Mary 115 1 50.00
John 100 2 100.00
Mike 121 7 700.00
[/tt]
It is assumed that the price for each item is the same for all customers. Also if there is no other record with a customer purchasing that item then it's OK to leave the field null.
Thanks for your help.
[tt]
customer item quantity total_cost
-------- ---- -------- ----------
Bob 121 4 400.00
Mary 115 1 50.00
John 100 2 100.00
Mike 121 7 [NULL]
[/tt]
I want to select all the records from the table however, for Mike instead of displaying NULL for the total cost I need the query to somehow CALCULATE the total_cost by finding another customer who bought the item and then dividing their total_cost by their quantity and then multiplying it by the quantity for the customer who is missing the value.
So for Mike you would have 400.00 (Bob's total) / 4 (Bob's quantity) * 7 (Mike's quantity) = 700.00 and the results would look like:
[tt]
customer item quantity total_cost
-------- ---- -------- ----------
Bob 121 4 400.00
Mary 115 1 50.00
John 100 2 100.00
Mike 121 7 700.00
[/tt]
It is assumed that the price for each item is the same for all customers. Also if there is no other record with a customer purchasing that item then it's OK to leave the field null.
Thanks for your help.