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

ROWID function [Miscellaneous] Next Page

ROW_NUMBER function [Miscellaneous]


Assigns a unique number to each row. Use this function instead of the NUMBER function.

Syntax

ROW_NUMBER( ) 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 returns a result set that provides unique row numbers for each of employees in New York and Utah. Because the query is ordered by Salary in descending order, the first row number is given to the employee with the highest salary in the data set. Although two employees have identical salaries, the tie is not resolved because the two employees are assigned unique row numbers.

SELECT Surname, Salary, State,
ROW_NUMBER() 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.000NY8
Driscoll48023.690UT9
Hildebrand45829.000UT10
............
Lynch24903.000UT19