Hi smile,
Refer below sample query.
SQL
DECLARE @tblSetMarks AS TABLE(AdmissionNo VARCHAR(10),SubjectID VARCHAR(MAX),Obtain INT, Max INT)
INSERT INTO @tblSetMarks VALUES('R-000501','128',34,50)
INSERT INTO @tblSetMarks VALUES('R-000502','128',43 ,50)
INSERT INTO @tblSetMarks VALUES('R-000503','128',34,50)
INSERT INTO @tblSetMarks VALUES('R-000504','128',5 ,50)
INSERT INTO @tblSetMarks VALUES('R-000505','128',32,50)
INSERT INTO @tblSetMarks VALUES('R-000501','129',21,50)
INSERT INTO @tblSetMarks VALUES('R-000502','129',25,50)
INSERT INTO @tblSetMarks VALUES('R-000503','129',45,50)
INSERT INTO @tblSetMarks VALUES('R-000504','129',43,50)
INSERT INTO @tblSetMarks VALUES('R-000505','129',32,50)
INSERT INTO @tblSetMarks VALUES('R-000501','130',44,50)
INSERT INTO @tblSetMarks VALUES('R-000502','130',34,50)
INSERT INTO @tblSetMarks VALUES('R-000503','130',23,50)
INSERT INTO @tblSetMarks VALUES('R-000504','130',23,50)
INSERT INTO @tblSetMarks VALUES('R-000505','130',47,50)
SELECT AdmissionNo,SubjectID,Max, Obtain
,rank() over(partition BY SubjectID order by Obtain DESC) AS Rank
FROM @tblSetMarks
ORDER BY AdmissionNo,SubjectID