Reputation: 860
I have a Marks table where i have a column marks_score and i want to add a Rank column using select query using Order BY Marks_score Desc.
I dont know how to use RANK() SQL Function
thanks in advance!!!
Upvotes: 1
Views: 706
Reputation: 24046
try this:
SELECT *,RANK() OVER (order by marks_score desc) as rnk
FROM Marks
You can find more examples here
Same way You can use ROW_NUMBER(), DESNSE_RANK() functions..
Please read this article to find the difference between them
Upvotes: 1
Reputation: 1916
Use this:
RANK() OVER (ORDER BY TOTAL_CNT DESC DESC) AS Rank
select t1.*,RANK() OVER (ORDER BY t1.Marks_score DESC) AS Rank from Marks as t1
Upvotes: 3