RANK
ranking
What changes
- Input
- partition and ORDER BY columns of OVER
- Output or change
- one rank or number per row
- Return type
- bigint
Syntax at a glance
RANK ( ) OVER ( [ partition_by_clause ] order_by_clause )
Work example
Rank scores while giving tied values the same position.
Create a tie and compare RANK with DENSE_RANK on the same ordered rows.
Check your work RANK leaves gaps after ties, so positions can jump.
Practice SQL
Open in SQL FlowSELECT score, RANK() OVER (ORDER BY score DESC) AS place FROM (VALUES (90), (90), (80)) AS v(score);
Open Microsoft Learn for full syntax, permissions, and details for your version.