I am attempting to write a short SQL query (in MySQL Workbench) that outputs the number of fails in a subject if it has been failed by more than one student.
Here's my attempt:
SELECT CONCAT(area, yearlevel, code) AS SubjectCode, Count(student)
FROM StudentTakesSubject
WHERE result < 50 AND result <> NULL
GROUP BY code
HAVING Count(Student) > 1;
The problem is it keeps outputting the count which contains the Null record even though I have specified in the query to not count them (or at least I thought I did...).
EDIT :
It was the GROUP BY clause that went wrong! As Gordon Linoff has pointed out in his answer, it should have been GROUP BY SubjectCode and that magically solved the problem.
Thank you all for the constructive insights.