I am building a query that gives the following information
Total Claims, Total Charges, Total Payment, Denial Count, % of Billed Charges and % of Claims Denied
This is all grouped by provider id, provider name and denied count then ordered by Total Claims.
I have been successful with my query until it comes to getting the % of Billed Charges and % OF Claims denied. You will see below my attempt to build a query in the select portion of the statement which of course did not work at all. When I -- the statement the query works so I know the mistake is specifically on that statement. I'm thinking it would as well need to be in one of the joins.....
I have no clue how to perform this type of aggregate. I need to have the % grouped by the provider as the count and sums are in the select statement and joins
Total Claims, Total Charges, Total Payment, Denial Count, % of Billed Charges and % of Claims Denied
This is all grouped by provider id, provider name and denied count then ordered by Total Claims.
I have been successful with my query until it comes to getting the % of Billed Charges and % OF Claims denied. You will see below my attempt to build a query in the select portion of the statement which of course did not work at all. When I -- the statement the query works so I know the mistake is specifically on that statement. I'm thinking it would as well need to be in one of the joins.....
I have no clue how to perform this type of aggregate. I need to have the % grouped by the provider as the count and sums are in the select statement and joins
Code:
SELECT
P.PRPR_ID ,
P.PRPR_NAME AS "Provider Name",
COUNT(C.CLCL_ID) AS "Total Claims",
SUM (CL.CDML_CHG_AMT) AS "Total Charges",
SUM (CL.CDML_PR_PYMT_AMT) AS "Total Payment",
ISNULL(C2.Denied_Count,0) Denied_Count
--(SUM(CL.CDML_PR_PYMT_AMT)/SUM(CL.CDML_CHG_AMT))FROM DW.FAC_CMC_CDML_CL_LINE CL AS "% of Billed Charges"
FROM DW.FAC_CMC_CLCL_CLAIM C
LEFT JOIN DW.FAC_CMC_PRPR_PROV P
ON C.PRPR_ID = P.PRPR_ID
LEFT JOIN DW.FAC_CMC_CDML_CL_LINE CL
ON C.CLCL_ID = CL.CLCL_ID
LEFT JOIN (SELECT P.PRPR_ID, COUNT (DISTINCT C.CLCL_ID) AS Denied_Count
FROM DW.FAC_CMC_CLCL_CLAIM C
JOIN DW.FAC_CMC_PRPR_PROV P
ON C.PRPR_ID = P.PRPR_ID
WHERE C.CLCL_TOT_PAYABLE = '0.00'
AND C.CLCL_LOW_SVC_DT >= '07/01/2015'
AND C.PRPR_ID IN ('x', 'y', 'z')
GROUP BY P.PRPR_ID
) c2 on C.PRPR_ID=c2.PRPR_ID
WHERE C.CLCL_LOW_SVC_DT >= '07/01/2015'
AND C.PRPR_ID IN ('x', 'y', 'z')
AND C.CLCL_CUR_STS IN ('01', '02')
GROUP BY
P.PRPR_ID ,
P.PRPR_NAME,
C2.Denied_Count
ORDER BY [Total Claims] DESC