Tag Archives: sql

Calculate a Percent of Total in Oracle SQL Query Using RATIO_TO_REPORT and OVER ()

Thanks to gpmilliken

Here’s a quick way to calculate a percentage of total count of events in a query.

SELECT B.PROGRAM_NAME_ID,
         ROUND (RATIO_TO_REPORT (COUNT (*)) OVER () * 100, 2) || ‘%’
            PERCENTOUTAGE
    FROM XFD_PROGRAMS B
GROUP BY PROGRAM_NAME_ID;