查询以查找在所有位置工作的员工

时间:2017-06-08 00:43:35

标签: sql

想象一下简单的员工数据库: 员工SELECT [Business].Name FROM Businesses as [Business] Left Outer JOIN Payments as [Payment] ON [Payment].BusinessId = [Business].Id Where [Business].Id is null and [Payment].TaxYear = 2016

我们希望找到在所有地方工作的员工?

不寻找特定的SQL服务器。

1 个答案:

答案 0 :(得分:1)

这适用于SQL Server(或任何支持count(distinct <column>)的数据库:

SELECT empId
FROM Employee
GROUP BY empId
HAVING COUNT(DISTINCT location) = (SELECT COUNT(DISTINCT location) FROM Employee)