:
SELECT users.Forename, users.Surname, count(grades.id) AS TotalGrades
FROM tblUsers AS users
INNER JOIN tblGrades AS grades ON users.ID=grades.UserID
WHERE grades.Grade in ("A","B","C") group by users.ID;
This is a simple join table. It basically means. Select all cases where the user has a rating of “A” or “B” or “C” (which will give you a table like this:
user1 | A
user1 | B
user1 | A
user2 | A
...
And then he groups it by users, counting how many times the class → appeared, giving you the number of ratings in the right range for each user.
source
share