Oracle9i SQL Reference
Release 1 (9.0.1)

Part Number A90125-01
Go To Documentation Library
Home
Go To Product List
Book List
Go To Table Of Contents
Contents
Go To Index
Index

Master Index

Feedback

Go to previous page Go to beginning of chapter Go to next page

Functions, 35 of 166


DENSE_RANK

Aggregate Syntax

dense_rank_aggregate::=


Text description of functions67.gif follows
Text description of dense_rank_aggregate

Analytic Syntax

dense_rank_analytic::=


Text description of functions86a.gif follows
Text description of dense_rank_analytic

See Also:

"Analytic Functions" for information on syntax, semantics, and restrictions 

Purpose

The DENSE_RANK function computes the rank of a row in an ordered group of rows. The ranks are consecutive integers beginning with 1. The largest rank value is the number of unique values returned by the query. Rank values are not skipped in the event of ties. Rows with equal values for the ranking criteria receive the same rank.

Aggregate Example

The following example computes the ranking of a hypothetical employee with the salary $15,500 and a commission of 5% in the sample table oe.employees:

SELECT DENSE_RANK(15500, .05) WITHIN GROUP 
   (ORDER BY salary DESC, commission_pct) "Dense Rank" 
   FROM employees;

         Dense Rank
-------------------
                  3

Analytic Example

The following statement selects the department name, employee name, and salary of all employees who work in the HUMAN RESOURCES or PURCHASING department, and then computes a rank for each unique salary in each of the two departments. The salaries that are equal receive the same rank. Compare this example with the example for RANK.

SELECT d.department_name, e.last_name, e.salary, DENSE_RANK() 
   OVER (PARTITION BY e.department_id ORDER BY e.salary) as drank
   FROM employees e, departments d
   WHERE e.department_id = d.department_id
   AND d.department_id IN ('30', '40');

DEPARTMENT_NAME         LAST_NAME              SALARY      DRANK
----------------------- ------------------ ---------- ----------
Purchasing              Colmenares               2500          1
Purchasing              Himuro                   2600          2
Purchasing              Tobias                   2800          3
Purchasing              Baida                    2900          4
Purchasing              Khoo                     3100          5
Purchasing              Raphaely                11000          6
Human Resources         Marvis                   6500  

Go to previous page Go to beginning of chapter Go to next page
Oracle
Copyright © 1996-2001, Oracle Corporation.

All Rights Reserved.
Go To Documentation Library
Home
Go To Product List
Book List
Go To Table Of Contents
Contents
Go To Index
Index

Master Index

Feedback