I have a table which holds grades of students based on three categories. There are five grades (A,B,C,D,E) per category, so the table looks something like this:
id | cat1 | cat2 | cat3
1 A B A
2 D C D
3 B A E
4 C B D
etc
I have a second table that list the grades
grade
A
B
C
D
E
I need to be able to run a query on this data so that I can count the number of grades achieved in each category for each grade. Something like this:
Cat1 | Cat2 | Cat 3
A 1 1 1
B 1 2 0
C 1 1 0
D 1 0 2
E 0 0 1
I have ran the following query, which I know is not correct, but is yielding results close to expected:
SELECT g.grade, COUNT( mb.cat1) , COUNT( mb.cat2) , COUNT( mb.cat3)
FROM markbook mb, grades g
WHERE g.grade = mb.cat1
GROUP BY g.grade