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;

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s