Am developing a school report card system .
The student can done 14 subjects but on grading, the system should pick on the best 8 done subject and SUM the points of the 8 subject . The system use this SUM to grade the student. I tried to use ORDER BY point ASC and LIMIT 8 , this display the best 8 done subject but when it comes to SUM it SUM the points of all subjects done by the student.
What could be the problem?
SELECT stid, subid, total, point FROM oresults WHERE stid= '2' ORDER BY point ASC;
+-------+-------+-------+
| subid | total | point |
+-------+-------+-------+
| 3 | 78.5 | 1 |
| 10 | 71.5 | 2 |
| 12 | 65 | 4 |
| 9 | 61 | 4 |
| 4 | 62.5 | 4 |
| 5 | 56.5 | 5 |
| 8 | 55 | 6 |
| 14 | 52 | 6 |
| 6 | 50.5 | 6 |
| 1 | 45 | 8 |
| 11 | 31.5 | 9 |
| 13 | 39.5 | 9 |
| 7 | 37.5 | 9 |
| 2 | 28.5 | 9 |
+-------+-------+-------+
SELECT stid, subid, total, point FROM oresults WHERE stid= '2' ORDER BY point ASC LIMIT 8;
+-------+-------+-------+
| subid | total | point |
+-------+-------+-------+
| 3 | 78.5 | 1 |
| 10 | 71.5 | 2 |
| 12 | 65 | 4 |
| 9 | 61 | 4 |
| 4 | 62.5 | 4 |
| 5 | 56.5 | 5 |
| 8 | 55 | 6 |
| 14 | 52 | 6 |
+-------+-------+-------+
SELECT sum(point) FROM oresults WHERE stid= '2' ORDER BY point ASC LIMIT 8;
+------------+
| SUM(point) |
+------------+
| 82 |
+------------+
- List item