cume_dist vs percent_rank or difference between

Are you asking what these functions do?

http://docs.oracle.com/cd/B19306_01/server.102/b14200/functions035.htm

CUME_DIST calculates the cumulative distribution of a value in a group of values.

In your example this means that ~29% has less or equal height than buddy. ~57% has less or equal height than lauren. Etc.

http://docs.oracle.com/cd/B19306_01/server.102/b14200/functions109.htm

PERCENT_RANK is similar to the CUME_DIST (cumulative distribution) function. The range of values returned by PERCENT_RANK is 0 to 1, inclusive. The first row in any set has a PERCENT_RANK of 0. The return value is NUMBER.


These two values are calculated differently - check out the manuals for these two functions: cume_dist and percent_rank

  1. CUME_DIST() over_clause

Returns the cumulative distribution of a value within a group of values; that is, the percentage of partition values less than or equal to the value in the current row. This represents the number of rows preceding or peer with the current row in the window ordering of the window partition divided by the total number of rows in the window partition. Return values range from 0 to 1.

  1. PERCENT_RANK() over_clause

Returns the percentage of partition values less than the value in the current row, excluding the highest value. Return values range from 0 to 1 and represent the row relative rank, calculated as the result of this formula, where rank is the row rank and rows is the number of partition rows: (rank - 1) / (rows - 1)

In your example, for the first row, cume_dist would return 2/7 because there are 2 values (15) smaller than or equal to the current row value (15), out of 7 rows; percent_rank would return 0 because (1-1) / (7-1) = 0.

Tags:

Sql

Oracle

Plsql