I am having some difficulties figuring out this SQL statement.
Here is the schema of the table.
studentID |subjectID | attendanceStatus | classDate |
1234567 ... 1 .....
1234567 ... 0
Basically I want to count the attendance percentage based on the studentID and display them in columns like this
studentID | subjectID | attendancePercentage
attendancePercentage is the number of 0s / total entries for that student
Here is what I did and it wasn’t giving the desired results.
SELECT studentID, COUNT(attendanceStatus = 0) AS Absent,
COUNT( attendanceStatus = 1) As Present
FROM attendance WHERE studentID = '1234567';
That failed.
I hope that I made sense of what I am trying to achieve.
I think you need use sum instead.