fetching a row from table

Having this data:

enter image description here

I am running this code:

SELECT student_info.student_name,student_info.department,student_info.marks,
rank() over (order by student_info.marks desc) score  from student_info ;

and getting:

enter image description here

I want first two records alone with rank with out using rownum

Upvotes: 0

Views: 46

Answers (1)

Zaid Parkar
Zaid Parkar

Reputation: 74

Can you try this please, I think this is what you need

SELECT student_name, department, marks, score
  FROM (SELECT s.*, RANK() OVER (ORDER BY marks DESC) AS score
          FROM student_info s)
 WHERE score = 1

Upvotes: 2

Related Questions