I'm using Delphi 2010 & MySQL in an application, I am facing a problem to calculate the sum of Services Debit Side, and the payment at credit side in one table, I'd like to get the Balance sheet. according to the Sum(Credit)-Sum(Debit).
IF (Sum(Credit)>Sum(Debit) , Sum(Credit)-Sum(Debit), 0) as creditBalance
IF (Sum(Debit>Sum(Credit), , Sum(Debit)-Sum(Credit), 0) as DebitBalance queryif.png
select ...
case when sum(credit) > sum(debit)
then sum(credit) - sum(debit)
else 0
end as creditbalance,
case when sum(debit) > sum(credit)
then sum(debit) - sum(credit)
else 0
end as debitbalance
case when sum(credit) > sum(debit)
then sum(credit) - sum(debit)
else 0
end as creditbalance,
case when sum(debit) > sum(credit)
then sum(debit) - sum(credit)
else 0
end as debitbalance