i have an exams table with students scores for each subject in the same table. the problem is that i want to have a rank for each subject of a student. for example what is the students rank in english. the problem is that the ranking seems to be done by comparing all the students subjects. therefore not giving an accurate result.
this is code i have tried.
$query7 =("SELECT * FROM (SELECT distinct Student_id, Subject, Total_Overal, RANK() OVER (PARTITION BY Subject ORDER BY Total_Overal DESC) as StudentRank FROM exams) t WHERE Student_id='$gradeid' and Subject='$sub' ");
$result7 = mysqli_query($conn,$query7);
//echo $row['rank'];
while($row2 = mysqli_fetch_array($result7))
{
//print_r(array_keys($row2));
//echo $num++;
//echo $row2[‘StudentRank’];
echo “”; echo $row2[‘StudentRank’];
}
i have only 40 students but the ranking is more than 40