To show the difference practically please
create a new table named dense_rank_demo for demonstration:
CREATE TABLE dense_rank_demo (
col VARCHAR2(10) NOT NULL
);
Next, insert some values into the dense_rank_demo table:
INSERT ALL
INTO dense_rank_demo(col) VALUES('A')
INTO dense_rank_demo(col) VALUES('A')
INTO dense_rank_demo(col) VALUES('B')
INTO dense_rank_demo(col) VALUES('C')
INTO dense_rank_demo(col) VALUES('C')
INTO dense_rank_demo(col) VALUES('C')
INTO dense_rank_demo(col) VALUES('D')
SELECT 1 FROM dual;
SELECT
col, RANK () OVER ( ORDER BY col ) My_rank,
DENSE_RANK () OVER ( ORDER BY col ) My_rank
FROM dense_rank_demo
SQL> /
COL MY_RANK MY_DENSE_RANK
---------- --------- -------------
A 1 1
A 1 1
B 3 2
C 4 3
C 4 3
C 4 3
D 7 4
7 rows selected.
No comments:
Post a Comment