Adu
Adu

Reputation: 381

SQL Query to retrieve result without duplication

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

Answers (2)

niko
niko

Reputation: 1

SELECT TeacherName, ClassTakenDate, COUNT( * ) AS NoOfDays 
FROM (
    SELECT DISTINCT TeacherName, ClassTakenDate
      FROM Schedule 
) AS foo
GROUP BY foo.ClassTakenDate

Upvotes: 0

Martin Smith
Martin Smith

Reputation: 453037

SELECT TeacherName, 
       COUNT(DISTINCT ClassTakenDate) AS NoOfDays
FROM Schedule 
GROUP BY TeacherName

Upvotes: 2

Related Questions