Very simply, I need to find student grades using SQL.
If, for example, I have following table that define grades
Marks (int)
Grade (Char)
and the data like this:
Marks | Grade
__90 | A+
__80 | A
__70 | A-
__60 | B
__50 | C
__40 | D
Okay, having said that, if I have a student that gained marks 73, how do I calculate her grade using above gradings in SQL.
Thank you so much…
Since I didn’t find any way to do it using MySQL, I had to do some PHP programming to achieve the result. The goal is to get the closest value from gradings.
Okay suppose, we have the grades as defined in my question.
Step 1: Get grades from mysql ordered by Marks in ASC order (ASC order is important):
Step 2: Create an array variable “$MinGrades”. Loop through the result of above query. Suppose MySQL results are stored in “$Gradings” array. Now on each iteration, do the following:
Step 3: When loop ends, the “$MinGrades” array’s first element will be the closest value … DONE
Below is the PHP code that implements the above:
If you have some better approach, please mention here.
Thanks for your contribution…