Hello All,

I have several queries that generate various financial reports, by date ranges.
I've been trying to figure out a way to combine all these queries into one query
, if it's at all possible or if it's practical to combine them into one large
query. The single query I tried doesn't produce the proper results. The multiple
queries below do produce the desired results, but I'd like to combine them into
one single query, if it's possible.

TOTAL SUMMARY PAYIN's/PAYOUT's(single query)
select format(sum(po.refund_charge*.95),2) as RefundCharge,
format(sum(po.refund_check),2) as RefundCheck,
format(sum(po.chargeback*.95)+ (count(po.chargeback)*-15),2) as ChargeBack,
format(sum(po.badcheck)+ (count(po.badcheck)*-15),2) as Badcheck,
format(sum(pi.amt_charge*.95),2) as TotalCharge,
format(sum(pi.amt_check),2) as TotalCheck
from payhistory ph 
left join payin pi on pi.payid = ph.payid 
left join payout po on po.payid = ph.payid
where ph.paydate between '2001-09-01' and '2001-09-14'
---------------------------

MULTIPLE SMALL QUERIES:
(these queries do produce the desired results)
=======================================================
PAYOUTS:

Total Refunds(Charge):
select format(sum(p.refund_charge*.95),2) as RefundCharge
from payout p,payhistory ph 
where ph.paydate between '2001-09-01' and '2001-09-14'
and p.payid = ph.payid;

Total Refunds(Check):
select format(sum(p.refund_check),2) as RefundCheck
from payout p,payhistory ph 
where ph.paydate between '2001-09-01' and '2001-09-14'
and p.payid = ph.payid;

Total ChargeBack query:
select format(sum(p.chargeback*.95)+ (count(p.chargeback)*-15),2) as ChargeBack 
from payout p,payhistory ph 
where ph.paydate between '2001-09-20' and '2001-09-30' 
and p.payid = ph.payid;

Total BadCheck query:
select format(sum(p.badcheck)+ (count(p.badcheck)*-15),2) as Badcheck
from payout p,payhistory ph 
where ph.paydate between '2001-09-20' and '2001-09-30' 
and p.payid = ph.payid;
======================================================
PAYINS:

Total New/Renewals(Charge):
select format(sum(p.amt_charge*.95),2) as TotalCharge 
from payin p,payhistory ph where ph.paydate 
between '2001-09-01' and '2001-09-14' 
and p.payid = ph.payid;

Total New/Renewals(Check):
select format(sum(p.amt_check),2) as TotalCheck 
from payin p,payhistory ph where ph.paydate 
between '2001-09-01' and '2001-09-14' 
and p.payid = ph.payid;
======================================================

Appreciate any suggestion or help.

mysql database.

Mike(mickalo)Blezien
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Thunder Rain Internet Publishing
Providing Internet Solutions that work!
http://www.thunder-rain.com
Tel: 1(225)686-2002
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=


---------------------------------------------------------------------
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/           (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php

Reply via email to