Joey
Joey

Reputation: 3

How to count same values in different cell as 1 instead of increase by 1 by 1 sql

I'm trying to count the Total Number of Supervisors for each branch according to branch ID (B001, B002, B003). I'm trying to get the result like 'Sandy' counted as 1 and 'Mandy' counted as another (total 2 supervisors for B001) but after i executed, the result showed 3 (Sandy counted separately as 2 different values instead of 1). so, what should i do to make total number of supervisor in B001 branch becomes 2.

there are 3 B001 in that table, but the supervisors are only sandy and mandy which Supervisor Sandy is repeated. The result showed there are 3 supervisors after i executed, so how can i make it to 2?)

results shown: 2

SELECT Staff.BranchID,Branch.Manager AS ManagerName, COUNT (staff.Supervisor) AS TotalNumberofSupervisor FROM Staff INNER JOIN Branch ON Branch.BranchID = Staff.BranchID GROUP BY Staff.BranchID,Branch.Manager

Upvotes: 0

Views: 29

Answers (1)

Sukreet Roy Choudhury
Sukreet Roy Choudhury

Reputation: 180

I think "COUNT (distinct(staff.Supervisor))" instead of "COUNT (staff.Supervisor)" will help

Upvotes: 1

Related Questions