Results 1 to 4 of 4

Thread: Query to get rank result

  1. #1
    Junior Member
    Join Date
    Jul 2007
    Answers
    3

    Query to get rank result

    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


  2. #2
    Junior Member
    Join Date
    Feb 2007
    Answers
    5

    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.


  3. #3
    Moderator
    Join Date
    Jun 2007
    Answers
    2,074

    Re: Query to get rank result

    If using oracle then order by mark in descending order and then finally display the rownum as rank.


  4. #4
    Expert Member
    Join Date
    Apr 2007
    Answers
    500

    Re: Query to get rank result

    Quote Originally Posted by beharavenkata View Post
    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
    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


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