I'm trying to rewrite an old Oracle SQL query I inherited and there is one part I don't understand. My new version comes up with about a dozen extra records and I've concluded it's because the HAVING clause in the original version is filtering them out(I removed the HAVING statement from my new query). I don't understand what the 'NOT IN (99, -99) is doing. If I remove the NOT IN I get an 'ORA-00920: invalid relational operator" error. If I change the 99, -99 to any other number the records still get filtered out.
Does anyone understand what the NOT IN (99, -99) is doing? I've never seen anything like this before.
HAVING
(sum(case
when (BD.EXPERIENCE_RATING_DESC) = 'RATED'
AND BD.BENEFIT_CATEGORY<>'INTEREST'
THEN CFCT.REPORTED_AMOUNT ELSE 0.00 END)
NOT IN (99,-99)
AND sum(case
when (BD.EXPERIENCE_RATING_DESC) = 'POOLED'
AND BD.BENEFIT_CATEGORY<>'INTEREST'
THEN CFCT.REPORTED_AMOUNT ELSE 0.00 END)
NOT IN (99,-99)
If either SUM equals 99 or -99, filter that (aggregated) row out.
It may make more sense if you add the SUM values to your SELECT list if they are not there already, and then (temporarily) reverse the HAVING clause by removing the word "NOT" in both cases. The results should all be rows that have SUM values of either 99 or -99.