Assigns a unique number to each row. Use this function instead of the NUMBER function.
ROW_NUMBER( ) OVER ( window-spec )
window-spec : see the Remarks section below
Elements of window-spec can be specified either in the function syntax (inline), or 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 cannot specify a ROWS or RANGE clause. See the window-spec definition for the 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 ROW_NUMBER is part of optional SQL/2008 language feature T611, "Elementary OLAP operations".
The following statement returns a result set that provides unique row numbers for each employee 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 GROUPO.Employees WHERE State IN ('NY','UT');
Discuss this page in DocCommentXchange.
|Copyright © 2014, SAP AG or an SAP affiliate company. - SAP Sybase SQL Anywhere 16.0|