SQLite RANK() Function
Example
Rank the products by price:
SELECT ProductName, Price,
RANK() OVER (ORDER BY Price DESC) AS Rnk
FROM Products;
Try it Yourself »
Definition and Usage
The RANK() function gives each row a rank. Rows with the same value get the same rank, and the next rank skips numbers. For example: 1, 2, 2, 4.
Note: Window functions need an OVER clause. Read more in the SQLite Window Functions chapter.
Tip: Also look at DENSE_RANK(), ROW_NUMBER().
Syntax
RANK() OVER (PARTITION BY column ORDER BY column)
Technical Details
| Return type: | Integer |
|---|---|
| Works in: | SQLite 3.25.0 and later |