Search notes:

Oracle SQL: ROW_NUMBER, RANK and DENSE_RANK

create table tq84_abc (
  val    number,
  text   varchar2(20)
);

insert into tq84_abc values (5, 'foo five');
insert into tq84_abc values (4, 'bar four');
insert into tq84_abc values (6, 'foo six (a)');
insert into tq84_abc values (7, 'baz seven');
insert into tq84_abc values (6, 'foo six (b)');
insert into tq84_abc values (6, 'foo six (c)');
insert into tq84_abc values (7, 'foo seven');

select
  val,
  text,
  row_number() over (order by val) rn,
  rank      () over (order by val) rk,
  dense_rank() over (order by val) dk
from
  tq84_abc
order by
  val;

drop table tq84_abc purge;
Github repository Oracle-Patterns, path: /SQL/select/analytical_functions/row_number-vs-rank-vs-dense_rank.sql

See also

Using dense_rank to select the number of distinct values in a group.
Using row_number to hierarchically structure a query result.
row_number() vs rank() vs dense_rank()
Analytic functions

Index

Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 8 attempt to write a readonly database in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php:78 Stack trace: #0 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(78): PDOStatement->execute(Array) #1 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(30): insert_webrequest_('/notes/developm...', 1759420056, '216.73.216.42', 'Mozilla/5.0 App...', NULL) #2 /home/httpd/vhosts/renenyffenegger.ch/httpsdocs/notes/development/databases/Oracle/SQL/select/analytic/ranking/row_number-rank-dense_rank/index(71): insert_webrequest() #3 {main} thrown in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php on line 78