I think its easiest to get all the rows you want, then iterate over each student id and add up all the A's, B's, etc for that student. Actually, I'm not entirely sure I understand what you are after.
Otherwise, to try and get a query that returns what you want, I made a terrible cludge using a temporary table that is SLOW:
create temporary table tmp(id int, grade char(1), sum int );
insert into tmp select student_id as id, grade, count(grade) from exam_result group by grade;
-- did limit just to return a few rows
select tmp.grade, sum, student_id, subject_id from tmp left join exam_result on student_id=tmp.id order by student_id, subject_id limit 50;
-- press return, then wait 5 seconds for results!
-- get something like this
grade sum student_id subject_id
A 9 1 1
A 9 1 2
A 9 1 3
...
drop the tmp table when you are done.