Click here to view and discuss this page in DocCommentXchange. In the future, you will be sent there automatically.

SQL Anywhere 10.0.1 » SQL Anywhere Server - SQL Reference » SQL Functions » Alphabetical list of functions

RAND function [Numeric] Next Page

RANK function [Ranking]


Calculates the value of a rank in a group of values. In the case of ties, the RANK function leaves a gap in the ranking sequence.

Syntax

RANK( ) OVER ( window-spec )

window-spec : see the Remarks section below

Remarks

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.

See also
Standards and compatibility
Example

The following example provides a rank in descending order of employees' salaries in Utah and New York. Notice that the 7th and 8th employees have an identical salary and therefore share the 7th place ranking. The employee that follows receives the 9th place ranking, which leaves a gap in the ranking sequence (no 8th place ranking).

SELECT Surname, Salary, State,
RANK() OVER (ORDER BY Salary DESC) "Rank"
FROM Employees WHERE State IN ('NY','UT')
SurnameSalaryStateRank
Shishov72995.000UT1
Wang68400.000UT2
Cobb62000.000UT3
Morris61300.000UT4
Davidson57090.000NY5
Martel55700.000NY6
Blaikie54900.000NY7
Diaz54900.000NY7
Driscoll48023.690UT9
Hildebrand45829.000UT10
Whitney45700.000NY11
............
Lynch24903.000UT19