Articles → SQL SERVER → Rank() Function In SQL Server

Rank() Function In SQL Server






Purpose





Syntax


RANK() OVER ( [PARTITION BY <column(s)>] ORDER BY <expression(s)> )



Example




Picture showing the sample table data in sql server




SELECT 
    order_id,
    product_id,
    quantity, price,
    RANK() OVER (ORDER BY quantity DESC) AS SalaryRank
FROM orders;



Output


Picture showing the output of rank function in sql server





Posted By  -  Karan Gupta
 
Posted On  -  Monday, October 14, 2024

Query/Feedback


Your Email Id
 
Subject
 
Query/FeedbackCharacters remaining 250