如何将不同单元格中的相同值计为1而不是将1乘以1 sql

时间:2017-04-25 17:31:26

标签: sql

我试图根据分行ID(B001,B002,B003)计算每个分支的监督总数。我试图得到像Sandy' Sandy'算作1和'Mandy'计算为另一个(B001总共2个监督员),但在我执行后,结果显示3(Sandy分别计为2个不同的值,而不是1)。那么,我应该怎样做才能使B001分公司的主管总数变为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?)

结果显示: 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

1 个答案:

答案 0 :(得分:1)

我认为" COUNT(不同(staff.Supervisor))"代替 " COUNT(staff.Supervisor)"会有所帮助