Friday, March 21, 2008

Query to display Rank


Hi,Suppose we have a table with fields

Rollno Name Marks

1 A 95

2 B 90

3 C 75

4 D 80

5 E 85

Write a query to display rollno,name,marks,Rank in ascending order of rank.

4 comments:

Unknown said...
This comment has been removed by the author.
Unknown said...

hi tanya!!!
i tried this using transformations rather than writing a query ...chk out i took marks in desc order with sorter and ranks in ascending using ranking hope this helps

Tanya said...

@Roopa,
This is an interview question and the need is to write a query rather than using transformation.The hint is use of Self Join.
Im still trying for the answer...

Tanya said...

Hi,
The answer for the query is as follows:
This can be done using a self join

SELECT A.ROLLNO,A.NAME,B.MARKS,RANK()OVER (ORDER BY B.MARKS DESC) FROM A1 A,A1 B WHERE A.ROLLNO=B.ROLLNO;

Regards
Tanya