I have a query that was given to me that I modified for my use. I'm having issue with the double of total billed amounts. However some accounts the aggregation is correct while in other accounts its double.
my sql is this.
SELECT DISTINCT
CNT.ACCT_ID,
COUNT(DISTINCT CNT.BILL_ID) AS BILLS,
TO_CHAR(SUM(CNT.CUR_AMT),'9,999,999') as TOTAL_BILLED,
TO_CHAR(SUM(CNT.CUR_AMT)/COUNT (DISTINCT CNT.BILL_ID),'999,999') as AVG_BILL
FROM
(SELECT
LC.ACCT_ID,
BILL.BILL_ID,
FT.CUR_AMT,
BILL.BILL_DT
FROM table1.CUSTOMER_DEPOSITS LC,
table2.PS_CI_BSEG BSEG,
table3.PS_CI_BILL BILL,
table4.PS_CI_FT FT
WHERE
LC.ACCT_ID =BILL.ACCT_ID
AND LC.CUST_CLASS NOT IN ('PPAY-R','TAFT','C-TAFT','SP3','C-NPAY')
AND FT.BILL_ID = BILL.BILL_ID
AND FT.FT_TYPE_FLG = 'BS'
AND BSEG.BILL_ID = BILL.BILL_ID
AND BSEG.BSEG_STAT_FLG = '50'
AND FT.ARS_DT > '01-JUN-2015'
AND FT.ARS_DT < '01-JUL-2016'
)CNT
GROUP BY CNT.ACCT_ID
I ran this against two accounts. One account had the correct total_billed amount while the second account had doubled the total_billed amount
I missing something but I honestly don't know how to resolve this. Any help would be greatly appreciated.