I want to calculate student rank based on their obtmarks as per below tables. Suppose any student scored highest marks in their class but he/she fail in any one subjects then th
If you don't want to include students with any failing grade then do a preliminary query to eliminate them. Then use that query to rank the remaining students. Consider:
Query1: Passing
SELECT resultdata.StudentID, Sum(resultdata.obtmarks) AS SumOfobtmarks
FROM resultdata
GROUP BY resultdata.StudentID
HAVING resultdata.StudentID Not In (SELECT resultdata.StudentID
FROM resultdata
WHERE resultdata.obtmarks<[passmarks]);
Query2:
SELECT Passing.SumOfobtmarks, Passing.StudentID,
(SELECT Count(*) FROM Passing AS T1 WHERE T1.SumOfobtmarks > Passing.SumOfobtmarks)+1 AS Rank
FROM Passing
ORDER BY Passing.SumOfobtmarks DESC;
However, if multiple students have same score, results will likely not be satisfactory. This is a common topic with many examples. For one review http://allenbrowne.com/ranking.html. Best solution might be one involving a 'temp' table as explained in Allen's article. Or try Lebans Serialize function, link is in Allen's article. Another excellent tutorial demonstrating these techniques http://www.mendipdatasystems.co.uk/rank-order-queries/4594424063.