请帮助我创建 SQL 查询。
我有两个表,公司和用户。users 表有 company_id 字段。
我需要计算有多少公司根本没有用户。
任何帮助都会很好!谢谢!
SELECT COUNT(*)
FROM companies a LEFT JOIN users b
on a.company_ID = b.company_ID
WHERE b.company_ID IS NULL
SELECT COUNT(*)
FROM companies c
WHERE NOT EXISTS
(
SELECT 1 FROM users u
WHERE u.company_id = c.company_id
)
SELECT COUNT(*)
FROM companies c LEFT JOIN users u
ON c.company_id = u.company_id
WHERE u.company_id IS NULL
Select Count(tblCompanies.ID)
From tblCompanies
left join tblUsers ON tblCompanies.ID = tblUsers.CompanyID
Where tblUsersID IS Null
Group By tblCompanies.ID