So, I have these 3 queries that return the exact data that I want:
I then want to insert this data into 3 tables and all seems to be ok:
Finally, I want to put them into one table:
Unfortunately, when I run this statement, it's wrong (every collector has same numAccts and same totalValue):
Any help would be greatly appreciated!!! Thanks in advance.
Code:
select assignedto, ifnull(count(*),0),portfolio,
sum(ifnull(round(paymentamount*contingencyamount/100,2),0)) from payments where paymentstatus='PENDING'
group by assignedto;
select assignedto, ifnull(count(*),0) ,portfolio,
sum(ifnull(round(paymentamount*contingencyamount/100,2),0)) from payments where paymentstatus='POSTED'
group by assignedto, portfolio;
select assignedto,ifnull(count(*),0) , portfolio,
sum(ifnull(round(originalbalance*contingencyamount/100,2),0))
from dbase group by assignedto, portfolio;
I then want to insert this data into 3 tables and all seems to be ok:
Code:
insert into indLiqPendTotal(collector, numPayments,portfolio_name, totalPending)
select assignedto, ifnull(count(*),0),portfolio,
sum(ifnull(round(paymentamount*contingencyamount/100,2),0)) from payments where paymentstatus='PENDING'
group by assignedto, portfolio;
insert into indLiqPostTotal(collector, numPayments,portfolio_name, totalPosted)
select assignedto, ifnull(count(*),0) ,portfolio,
sum(ifnull(round(paymentamount*contingencyamount/100,2),0)) from payments where paymentstatus='POSTED'
group by assignedto, portfolio;
insert into indLiqNumAccts(collector, numAccts,portfolio_name, totalValue)
select assignedto,ifnull(count(*),0) , portfolio,
sum(ifnull(round(originalbalance*contingencyamount/100,2),0))
from dbase group by assignedto, portfolio;
Finally, I want to put them into one table:
Code:
insert into indLiqReports(collector, portfolio_name, numAccts, numPendPayments, totalPending,
numPostPayments, totalPosted, totalNumPayments, totalValue)
select indLiqPostTotal.collector, indLiqPostTotal.portfolio_name, indLiqNumAccts.numAccts,
indLiqPendTotal.numPayments, indLiqPendTotal.totalPending, indLiqPostTotal.numPayments,
indLiqPostTotal.totalPosted, indLiqPendTotal.numPayments + indLiqPostTotal.numPayments,
indLiqNumAccts.totalValue from indLiqPendTotal, indLiqPostTotal, indLiqNumAccts
where indLiqPendTotal.collector = indLiqPostTotal.collector
and indLiqPendTotal.collector = indLiqNumAccts.collector group by collector, portfolio_name;
Unfortunately, when I run this statement, it's wrong (every collector has same numAccts and same totalValue):
Code:
select collector, portfolio_name as portfolio, numAccts as "number of accounts", numPendPayments,
totalPending, numPostPayments, totalPosted, totalNumPayments, totalValue,
round((((totalPosted+totalPending)/totalValue)*100),2) as "LiqRate" from indLiqReports group by portfolio,collector;
Any help would be greatly appreciated!!! Thanks in advance.