Watch the 7.3 Webinar On-Demand
This new release brings updates to Universal Storage, query
optimization, and usability that you won’t want to miss.
Ranking function. Returns the rank of the current row within the partition as specified by the order by clause. If two or more rows tie they have the same ranking. The difference between RANK
and DENSE_RANK
is that DENSE_RANK
does not skip values after a tie.
DENSE_RANK () OVER (
[PARTITION BY (col | expr), ...]
[ORDER BY (col | expr), ...]
)
Integer
create table example (a int, b int);
insert into example values(1,2),(2,2),(3,3),(4,3);
select a,b, dense_rank() over(order by b) from example;
+------+------+-------------------------------+
| a | b | dense_rank() over(order by b) |
+------+------+-------------------------------+
| 1 | 2 | 1 |
| 2 | 2 | 1 |
| 3 | 3 | 2 |
| 4 | 3 | 2 |
+------+------+-------------------------------+