There is a strong smell of homework here, so you will get no code!
How you do this will depend on your database design: you could do this with a single row in a single table:
StudentInfo, year1Data, year2Data, year3Data, year4Data
where each yearNData consisted of 8 subject marks.
Then the query is pretty simple: just use the SQL SUM function to add all the subject marks together.
That is a clumsy way to do it though: You would probably be better off with a Student table, a Year Table which refers to the student ID, and a Marks Table which refers to the year table. That makes teh query more complex, but provides more flexibility.
Or you could do it somewhere in the middle.
What kind of scheme do you have?