Reputation: 79
I want to count the No of PRESENT occurences in ATTENDANCE column for a specific STU_ID.
So far, I have tried...
SELECT COUNT(DISTINCT ATTENDANCE) FROM STUDENT WHERE STU_ID=40;
But its showing distinct values only but I want how many presents are there in the column for a particular student.
Upvotes: 0
Views: 65
Reputation: 497
By doing COUNT(DISTINCT ATTENDANCE), you are counting the distinct values in the STU_ID column. And how many are there, two? Just "PRESENT" and "NOT PRESENT"?
Try:
SELECT COUNT(*) AS AttendanceCount
FROM STUDENT
WHERE STU_ID = 40
AND ATTENDANCE = 'PRESENT'
Or if you want to see each student, do
SELECT STU_ID, COUNT(*) AS AttendanceCount
FROM STUDENT
WHERE ATTENDANCE = 'PRESENT'
GROUP BY STU_ID
Upvotes: 2