where 子句没有将记录缩小到我指定的范围

where clause is not narrowing down the records to what i have specified

有一些表格,我正在尝试将记录数加起来,但来自特定办公室。

SQL :

  SELECT  COUNT(*) AS "Number of employees" FROM staff, office
  WHERE office.office_id  =10;

所以希望 office = 10 的员工。因此该字段应显示为 "Number of employees" as 3.

而是将所有记录相加并显示“9”。

办公室 1 的 ID 为 10 办公室 2 的 ID 为 20

你一定在这两个 table 之间有某种关系。 staff table?

中的 officeId 之类的东西
select count(*) from staff,office where office.office_id=staff.office_id and office.office_id=10;

第一个条件是 link table,第二个条件是过滤它。

您必须连接 2 个表才能获得您想要的结果,例如:

   SELECT  COUNT(*) AS "Number of employees" FROM staff, office
   WHERE staff.office_id = office.office_id and office.office_id  =10;