Click here to Skip to main content
14,386,278 members
Rate this:
Please Sign up or sign in to vote.
See more:
sir/mam can I know how can I get the rank function in my SQL
I have tried in my SQL this the code I have tried but its showing error plz help me
SELECT subjects,names, marks, rank()
over ( partition by subjects order by marks desc )
AS 'rank' FROM result;
many people are saying that there is no over clause function in MySQL so how can i get rank function sir

What I have tried:

SELECT subjects,names, marks, rank() 
over ( partition by subjects order by marks desc ) 
AS 'rank' FROM result;
many people are saying that there is no over clause function in MySQL so how can i get rank function sir
Posted
Updated 24-Apr-19 10:26am
Comments
0x01AA 24-Apr-19 8:35am
   
a.) "it is showing error" ---> What is the error?
b.) One of the mySQL Tutorial: A Guide to MySQL RANK Funtion By Practical Examples[^]
Rate this:
Please Sign up or sign in to vote.

Solution 1

Just get the syntax right - see the documentation A Guide to MySQL RANK Funtion By Practical Examples[^]
Try this
SELECT subjects,names, marks, rank() 
over ( partition by subjects order by marks desc ) my_Rank
FROM result;
I've removed the AS and given it a name that is not a reserved word.
If it still doesn't work then it's likely that you are using an out-of-date version of MySQL as the "many people" who are saying there is no over clause in MySQL are wrong.
   
v2
Comments
0x01AA 24-Apr-19 13:14pm
   
Should work, a 5.
Maciej Los 24-Apr-19 15:20pm
   
Agree!
Rate this:
Please Sign up or sign in to vote.

Solution 2

   
Comments
0x01AA 24-Apr-19 15:37pm
   
Also good, a 5
Maciej Los 24-Apr-19 15:50pm
   
Thank you, Bruno.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100