DENSE_RANK Window Funtion
DENSE_RANK is a window function that returns the ranking of each row of the current partition
specified by the inline-window-specification. The ranking is relative to the ordering specified in
the inline-window-specification. The return value of DENSE_RANK starts at 1 for the first row
of the window. Values of the given expression that are equal have the same rank. The value of
DENSE_RANK advances 1 when the value of the given expression changes.
DENSE_RANK() OVER (inline-window-specification)
inline-window-specification is:
[PARTITION BY expression [, expression]...]
[ORDER BY expression [ASC[ENDING] | DESC[ENDING]]
inline-window-specification
specifies the window over which the DENSE_RANK is computed. The
inline-window-specification can contain an optional PARTITION BY clause and an
optional ORDER BY clause. The PARTITION BY clause specifies how the intermediate result
is partitioned and the ORDER BY clause specifies how the rows are ordered within each
partition.
Examples of DENSE_RANK Window Function
•
Return the dense rank for each employee based on employee number:
SELECT DENSE_RANK() OVER (ORDER BY empnum), *
FROM persnl.employee;
•
Return the dense rank for each employee within each department based on salary:
SELECT DENSE_RANK() OVER (PARTITION BY deptnum ORDER BY salary), *
FROM persnl.employee;
[,expression [ASC[ENDING] | DESC[ENDING]]]...]
DENSE_RANK Window Funtion
497