Good Morning,
I am wondering how I can add a column to this SQL script that will calculate the AVG(PROC_TIME).
If the PROC_NUMBER IS >= 10 Then the AVG should be grouped on MD_CODE, PROC_BLOCK_DESCRIPTION AND PROC_DESCRIPTION.
If the PROC_NUMBER IS < 10 Then I need it to display the AVG grouped on just the PROC_BLOCK_DESCRIPTION AND PROC_DESCRIPTION.
I am basically wanting a column that calculates the average procedure time per doctor, but if the doctor hasnt done 10 or more of a type of procedure then it will display the overall average across all the doctors for that procedure.
My code is
SELECT HOSP_CODE, PROC_DATE, OPP_PRO_SPECIALTY, MD_CODE, GIVEN_NAME, SURNAME, PROC_BLOCK_DESCRIPTION, PROC_DESCRIPTION, PROC_TIME, ROW_NUMBER() OVER (PARTITION BY MD_CODE, PROC_BLOCK_DESCRIPTION, PROC_DESCRIPTION ORDER BY PROC_DATE) AS PROC_NUMBER FROM #PROCEDURES ORDER BY MD_CODE, PROC_BLOCK_DESCRIPTION, PROC_DESCRIPTION
My output currently looks like this: