I have these two queries to test my output
SELECT DISTINCT( providerId ),
SUM(( claimCount )),
SUM(paidAmount),
SUM(provallowed),
SUM(patresp),
provId,
cliCode,
asctype,
payerid,
procCode
FROM TempCounts tt,
TempClient tct
WHERE ( tct.npi = tt.provid
OR tct.txcode = tt.provid )
AND CLICODE = 'XXX'
GROUP BY tt.provid,
providerId,
cliCode,
asctype,
payerid,
procCode
—
SELECT DISTINCT( providerid ),
claimCount,
paidamount,
provallowed,
patresp,
provid,
CLICODE,
asctype,
payerid,
proccode
FROM TempCounts tt,
TempClient tct
WHERE ( tct.npi = tt.provid
OR tct.txcode = tt.provid )
AND CLICODE = 'XXX'
summing the unaggregated results from the second query should give the aggregated values in the first query, but my data sets end up like
first data set
15086 7 216.16 0.00 35.00 1609950203 XXX 216 72040
15086 7 227.36 0.00 21.00 1609950203 XXX 216 72070
second data set
15086 1 30.88 0.00 5.00 1609950203 XXX 216 72040
15086 1 32.48 0.00 3.00 1609950203 XXX 216 72070
Can’t for the life of me see what I’m missing and stared at it so long I’m code blind. Any suggestions?
I figured it out finally. because the tempClient table has multiple records based on the npi and txcode field (i.e. a record can have multiple instances of txcode for each npi. I thought I was filtering for that as the same query against mysql gave correct results. The solution was adding tt.npi and tt.txcode to the groupby statement.