Reputation: 381
I have table named Schedule which has fields named TeacherName and ClassTakenDate.The values in the table are as shown below:
TeacherName ClassTakenDate
Anish 2011-10-01
Anish 2011-10-01
John 2011-10-01
John 2011-10-02
I want result like this :
TeacherName NoOfDays
Anish 1
John 2
how we can do this?
Upvotes: 1
Views: 55
Reputation: 1
SELECT TeacherName, ClassTakenDate, COUNT( * ) AS NoOfDays
FROM (
SELECT DISTINCT TeacherName, ClassTakenDate
FROM Schedule
) AS foo
GROUP BY foo.ClassTakenDate
Upvotes: 0
Reputation: 453037
SELECT TeacherName,
COUNT(DISTINCT ClassTakenDate) AS NoOfDays
FROM Schedule
GROUP BY TeacherName
Upvotes: 2