ROW_NUMBER, RANK, DENSE_RANK, NTILE
These are window functions used to rank and number rows in the result set.
Example: Using ROW_NUMBER
SELECT Name, City,
ROW_NUMBER() OVER (ORDER BY Name) AS RowNumber
FROM FreedomFighters;
Output:
Assigns a unique row number to each freedom fighter.
Notes
ROW_NUMBER
: Assigns a unique number to each row.RANK
: Assigns ranks to rows with gaps for duplicate values.DENSE_RANK
: Assigns ranks without gaps for duplicates.NTILE
: Divides the result set into a specified number of equal parts.