2012-04-17 56 views
-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。

任何想法?

+6

您所需要的搜索术语是“关系型师” – 2012-04-17 14:32:11

回答

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)