MySQL Forums
Forum List  »  PHP

Re: Display Query Result
Posted by: Peter Brawley
Date: May 15, 2015 02:05PM

Your `howmuch` sum query seems to be missing a table reference and a scope. Shouldn't it be like this?

select sum(howMuch) into MemPayment
from payment
where payer = officeId;

But why not do the whole computation in one query?

select 
  e.spender, 
  sum(e.cost) as totalexpenses,
  r.total,
  p.mempayment,
  r.total + p.mempayment as count,
  r.total + p.mempaymeny - e.totalexpenses as remaining
from expenses e
join (select raiser, sum(totalraised) as total      from raisedfund group by raiser) r on e.spender=r.raiser
join (select payer,  sum(howmuch)     as mempayment from payment    group by payer)  p on e.spender=p.payer
where e.spender=officeID
group by e.spender;

Options: ReplyQuote


Subject
Written By
Posted
May 15, 2015 12:11PM
Re: Display Query Result
May 15, 2015 02:05PM
June 01, 2015 01:32PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.