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

DEGREES function [Numeric] Next Page

DENSE_RANK function [Ranking]


Calculates the rank of a value in a partition. In the case of tied values, the DENSE_RANK function does not leave gaps in the ranking sequence.

Syntax

DENSE_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 returns a result set that provides a ranking of the employees' salaries in Utah and New York. Although 19 records are returned in the result set, only 18 rankings are listed because of a 7th-place tie between the 7th and 8th employee in the list, who have identical salaries. Instead of ranking the 9th employee as '9', the employee is listed as '8' because the DENSE_RANK function does not leave gaps in the ranks.

SELECT DepartmentID, Surname, Salary, State,
DENSE_RANK() OVER (ORDER BY Salary DESC) AS SalaryRank
FROM Employees 
WHERE State IN ('NY','UT');

Here is the result set:

SurnameSalaryStateSalaryRank
Shishov72995.000UT1
Wang68400.000UT2
Cobb62000.000UT3
Morris61300.000UT4
Davidson57090.000NY5
Martel55700.000NY6
Blaikie54900.000NY7
Diaz54900.000UT7
Driscoll48023.000UT8
Hildebrand45829.000UT9
Whitney45700.000NY10
Guevara42998.000NY11
Soo39075.000NY12
Goggin37900.000UT13
Wetherby35745.000NY14
Ahmed34992.000NY15
Rebeiro34576.000UT16
Bigelow31200.000UT17
Lynch24903.000UT18