0

请帮助我创建 SQL 查询。

我有两个表,公司和用户。users 表有 company_id 字段。

我需要计算有多少公司根本没有用户。

任何帮助都会很好!谢谢!

4

4 回答 4

2
SELECT COUNT(*)
FROM companies a LEFT JOIN users b
       on a.company_ID = b.company_ID
WHERE b.company_ID IS NULL
于 2012-11-16T14:24:57.740 回答
2
SELECT COUNT(*) 
FROM companies c
WHERE NOT EXISTS
(
  SELECT 1 FROM users u
  WHERE u.company_id = c.company_id
)
于 2012-11-16T14:25:33.477 回答
1
SELECT COUNT(*)
FROM companies c LEFT JOIN users u
ON c.company_id = u.company_id
WHERE u.company_id IS NULL
于 2012-11-16T14:25:44.337 回答
0
Select Count(tblCompanies.ID)
From tblCompanies
left join tblUsers ON tblCompanies.ID = tblUsers.CompanyID
Where tblUsersID IS Null
Group By tblCompanies.ID
于 2012-11-16T14:26:15.270 回答