Find the Rank or Position of Students or First and Second in a Group



First of all we create a table:

CREATE TABLE Student( [Name] [char](50) NULL, [Marks] [int] NULL)

  and insert some values in this table:

INSERT INTO Student VALUES ('Jacob', 70)INSERT INTO Student VALUES('Sophia', 72)INSERT INTO Student VALUES(' Mason', 54)INSERT INTO Student VALUES('Emma', 65)INSERT INTO Student VALUES('Ethan', 39)INSERT INTO Student VALUES('Isabella', 25)INSERT INTO Student VALUES('Noah', 87)INSERT INTO Student VALUES('Olivia', 67)INSERT INTO Student VALUES('William', 65)INSERT INTO Student VALUES(' Michael', 39)INSERT INTO Student VALUES('Kallis', 47)INSERT INTO Student VALUES('Ponting', 22)INSERT INTO Student VALUES('Sachin', 98)
select
* from Student
Output



 To find th rank click Here;

Query to find the Rank or Position


SELECT Name, Marks,
(
SELECT COUNT(*)+1 FROM Student B WHERE A.Marks<B.Marks) AS Rank FROM Student AORDER BY Marks DESC



Output is:

   



To See the Table Values Click here