-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 か国のサブリージョンの 1 つの国に存在する従業員ではなく、サブリージョンのみのすべての国に存在する従業員の名前が必要です。上記のデータの場合、クエリは 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

または1つのクエリで:

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