-1

表格1

Employee Name,Employee type, Country Present 

Jim Mith , Consulting,England
Jim Mith, Manfacturing, Scotland
Jim Mith, Consulting, Northern Ireland
Mavis Mith, Consulting, France
Jim Mith,Consulting, Wales

表 2

County Present , Corresponding SubReegion 

England, UK & I 
Scotland, UK & I 
Northern Ireland, UK& I
Wales, UK & I
France, CEE

我只想要一个子区域的所有国家/地区的员工姓名,而不是 5 个国家/地区的一个国家/地区的员工姓名。对于上述数据,查询应该只返回 Jim Mith。

有任何想法吗?

4

1 回答 1

1

从记忆中,您可以执行以下操作:

declare @totalCountries int
select @totalCountries = count(distinct CountryPresent) from table2


select EmployeeType
from table1
group by EmployeeType
having count(distinct CountryPresent) = @totalCountries

或仅在一个查询中:

select EmployeeType
    from table1
    group by EmployeeType
    having count(distinct CountryPresent) = (select count(distinct CountryPresent) from table2)
于 2012-04-17T14:33:33.943 回答