I am trying to identify claims that meet the following criteria:
- Each line must have denial code "X"
- One line must have an allowed amount that is greater than $0.00
- The remaining lines must have an allowed amount equal to $0.00
Example: Claim ID 123456 has three rows associated with this ID. Row 1 allowed $40.00. Rows 2 and 3 allowed $0.00. With this query Claim ID 123456 would pull.
The only way I can think of doing this is running a query for all claims that have denial code "X" and then manually searching in Excel.
Basically the query I have is:
SELECT DISTINCT
Claim ID,
Line Number,
Denial Code,
Line Allowed Amount
(FROM)
WHERE
Denial Code = 'X'
I would move what we can to the
where
clause and usehaving
clause to ensure that we only include those claimIds where only one row had amount > 0 with all other being 0, which is only possible whenmax(lineallowedamount) = sum(lineallowedamount)
is true.And if you want to get data from your table filtered for these claimids, you can use a subquery like below