For any row X, defined by the function's arguments and ORDER BY specification, the PERCENT_RANK function determines the rank of row X - 1, divided by the number of rows in the group.
PERCENT_RANK( ) OVER ( window-spec )
window-spec : see the Remarks section below
The PERCENT_RANK function returns a DOUBLE value between 0 and 1.
Elements of window-spec can be specified either in the function syntax (inline), or in conjunction with a WINDOW clause in the SELECT statement. When used as a window function, you must specify an ORDER BY clause, you may specify a PARTITION BY clause, however, you can not specify a ROWS or RANGE clause. See the window-spec definition provided in WINDOW clause.
For more information about using window functions in SELECT statements, including working examples, see Window functions.
For more information about specifying a window specification in an OVER clause, see Window definition: inlining using the OVER clause and WINDOW clause.
SQL/2008 PERCENT_RANK is part of optional SQL/2008 language feature T612, "Advanced OLAP operations".
The following example returns a result set that shows the ranking of New York employees' salaries by gender. The results are ranked in descending order and are partitioned by gender.
SELECT DepartmentID, Surname, Salary, Sex, PERCENT_RANK() OVER (PARTITION BY Sex ORDER BY Salary DESC) "Rank" FROM Employees WHERE State IN ('NY'); |
DepartmentID | Surname | Salary | Sex | Rank |
---|---|---|---|---|
200 | Martel | 55700.000 | M | 0 |
100 | Guevara | 42998.000 | M | 0.333333333 |
100 | Soo | 39075.000 | M | 0.666666667 |
400 | Ahmed | 34992.000 | M | 1 |
300 | Davidson | 57090.000 | F | 0 |
400 | Blaikie | 54900.000 | F | 0.333333333 |
100 | Whitney | 45700.000 | F | 0.666666667 |
400 | Wetherby | 35745.000 | F | 1 |
Discuss this page in DocCommentXchange.
|
Copyright © 2010, iAnywhere Solutions, Inc. - SQL Anywhere 12.0.0 |