Syntax
DENSE_RANK() OVER([ query_partition_clause ] order_by_clause)
Purpose
DENSE_RANK() returns the rank of a data row in the column that is specified in order_by_clause.
Ranks are consecutive integers. Rows with the same rank value have the same rank.
Examples
CREATE TABLE employees(LAST_NAME CHAR(10), SALARY DECIMAL, JOB_ID CHAR(32));
INSERT INTO employees VALUES('JIM', 2000, 'CLEANER');
INSERT INTO employees VALUES('MIKE', 12000, 'ENGINEERING');
INSERT INTO employees VALUES('LILY', 13000, 'ENGINEERING');
INSERT INTO employees VALUES('IRIS', 11000, 'ENGINEERING');
INSERT INTO employees VALUES('TOM', 11000, 'ENGINEERING');
COMMIT;
Query OK, 1 row affected
obclient> SELECT LAST_NAME, RANK() OVER(PARTITION BY JOB_ID ORDER BY SALARY) RANK, DENSE_RANK() OVER(PARTITION BY JOB_ID ORDER BY SALARY) DENSE_RANK, PERCENT_RANK() OVER(PARTITION BY JOB_ID ORDER BY SALARY) PERCENT_RANK FROM employees;
+-----------+------+------------+----------------------------------+
| LAST_NAME | RANK | DENSE_RANK | PERCENT_RANK |
+-----------+------+------------+----------------------------------+
| JIM | 1 | 1 | 0.000000000000000000000000000000 |
| TOM | 1 | 1 | 0.000000000000000000000000000000 |
| IRIS | 1 | 1 | 0.000000000000000000000000000000 |
| MIKE | 3 | 2 | 0.666666666666666666666666666667 |
| LILY | 4 | 3 | 1.000000000000000000000000000000 |
+-----------+------+------------+----------------------------------+
5 rows in set