RANK
A window function that gives tied rows the same position and then skips positions, as in 1, 2, 2, 4.
In more detail
It is how a sports table ranks: two joint seconds mean there is no third. Use DENSE_RANK when you want no gaps.
Example
RANK() OVER (ORDER BY price_cents DESC) AS price_rankRelated terms
- DENSE_RANK — A window function that gives tied rows the same position without leaving gaps, as in 1, 2, 2, 3.
- ROW_NUMBER — A window function that numbers rows 1, 2, 3 in the window's order, giving tied rows different numbers.
- window function — A calculation across a set of rows related to the current row that, unlike GROUP BY, keeps every input row in the answer.
Taught in
- Advanced Window Functions: Ranking And Framing — PostgreSQL, Indexing & Relational Data Modeling