Thanks! that worked great!
I ended up using the first one, I just liked the look of it better.
Because the customer might not have any deposit records or any
purchases I changed the code to this:
SELECT @purchases := SUM(amount_of_credit_used)
FROM purchases WHERE customer_id="jdoe";
I know there are more ways to solve this problem (I can think of at least
2 more) but I think the easiest approach is to break this into two stages.
First stage, we compute the sums of the purchases and the credits:
SELECT @purchases := SUM(amount_of_credit_used)
FROM purchases
WHERE customer_id
I hope this isn't a stupid question but this is my best place to ask...
I have a database where I need to do a sum of a returned select...
SELECT SUM(purchases.amount_of_credit_used) WHERE customer_id="jdoe";
and do a sum of another returned select...
SELECT SUM(amount) from deposits WHERE customer