Results 1 to 6 of 6

Thread: Query to display rank

  1. #1
    Junior Member
    Join Date
    Mar 2008
    Answers
    15

    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.


  2. #2
    Junior Member
    Join Date
    Sep 2007
    Answers
    13

    Re: Query to display rank

    use the query below, Its in Db2

    select rollno,name,marks from table_name order by marks asc

    cheers,
    Divya


  3. #3
    Junior Member
    Join Date
    Mar 2008
    Answers
    15

    Re: Query to display rank

    Hi Divya,

    Thanks for the suggestion.But Im using Oracle database
    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;

    I tried it..Its working....
    Regards
    Tanya


  4. #4
    Junior Member
    Join Date
    Mar 2008
    Answers
    2

    Re: Query to display rank

    hi,
    the query posted above executes perfectly,
    but remember if u r using oracle asc is default with order by clause no need to mention it
    select rollno,name,marks from table_name order by marks
    this will also do
    check it out


  5. #5
    Junior Member
    Join Date
    Mar 2008
    Answers
    15

    Re: Query to display rank

    @bmdirshad,
    I think you didnot go thr my query properly.I want the rank to be displayed in the query.
    Otherwise what you have mentioned would be correct.

    Regards
    Tanya


  6. #6
    Junior Member
    Join Date
    Mar 2008
    Answers
    2

    Re: Query to display rank

    HI Tanya,
    sorry i just went thru this query posted by one member.

    select rollno,name,marks from table_name order by marks asc

    i haven't gone thru the query that u posted using rank() coz it was not avail at that time

    so CHECK THIS QUERY WITHOUT USING RANK()

    select rownum as rank,rollno,name,marks
    from (select rollno,name,marks
    from a1
    order by marks desc)

    AND thanks FOR THAT QUERY

    Last edited by bmdirshad; 04-06-2008 at 03:16 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
About us
Applying for a job can be a stressful and frustrating experience, especially for someone who has never done it before. Considering that you are competing for the position with a at least a dozen other applicants, it is imperative that you thoroughly prepare for the job interview, in order to stand a good chance of getting hired. That's where GeekInterview can help.
Interact