I am trying to figure out a query in SQL Server where I have two tables, Grades & Courses. The query needs to return all the courses with a total count of students that received an ‘A’ for the quarter. Them result set should look like this:
Course Title Number of A’s
Math 1
Science 0
Geography 4
Economics 0
World History 2
I can get the query to return three of those rows…the ones with A’s but not other grades. The courses with 0 are obviously the ones where no A’s were passed out but they need to be included in the query.
This is my query below:your text
SELECT A.Title
COUNT(B.Grades) AS [Number of A's]
FROM Courses A LEFT JOIN on Grades B ON A.Course_ID = B.Course_ID
WHERE B.Grades = 'A'
GROUP BY B.Grades, A.Title
ORDER BY A.Course_ID