DENSE_RANK()
DENSE_RANK() is a SQL function in the Window Functions category. Like RANK but without gaps. Equal values get the same rank, and the next number follows sequentially. The syntax is DENSE_RANK() OVER (PARTITION BY column ORDER BY column). It accepts PARTITION BY column ORDER BY column. It returns rank integer (no gaps). A typical example: SELECT score, DENSE_RANK() OVER (ORDER BY score DESC) FROM exam_results; -- Scores: 100, 95, 95, 90 -- Ranks: 1, 2, 2, 3 (no gap) A close relative is ROW_NUMBER(), which assigns a unique sequential integer to each row within its partition (1, 2, 3...). A close relative is RANK(), which similar to ROW_NUMBER but gives the same rank to equal values. Leaves gaps in ranking. A close relative is LAG(), which accesses data from a previous row within the same result set (useful for comparing values). More about this category: Window/analytical functions — ROW_NUMBER, RANK, DENSE_RANK, LAG, LEAD, NTILE.