Re: Query to get rank result
Hi, One easy way to generate ranking is first select the records order by marks(in descending order).Then fetch record one by one and update the rank field.
Re: Query to get rank result
If using oracle then order by mark in descending order and then finally display the rownum as rank.
Re: Query to get rank result
[QUOTE=beharavenkata;23425]Hi,
I have two tables, table1(Id,Name) and Table2(Id,Marks). I want to give Rank based upon the Marks.
Ex:
Id Name Marks Rank
1 AA 100 1
2 BB 90 2
3 CC 80 3
4 DD 70 4
5 EE 60 5
I wrote the following query and not able to get the result, can any one suggest on this..
Select table1.Id,Table1.Name,table2.marks,Expr1: (select count(Table2.marks) from Table2 where table2.marks
Thanks,
Kishore[/QUOTE]
If ur using oracle then use this query
select TABLE1.ID,TABLE1.NAME,TABLE2.MARKS,
rank() OVER ( ORDER BY TABLE2.MARKS desc)
from TABLE1,TABLE2 WHERE TABLE1.ID=TABLE2.ID