Sql 查找GroupBy中存在于每个组中的行
我有一个临时表Sql 查找GroupBy中存在于每个组中的行,sql,Sql,我有一个临时表#People,其中包含以下内容: PersonnelId, TaskId 200 40 200 41 200 **42** 300 **42** 300 45 400 41 400 **42** 400 60 因此,请注意,所有三组人员中都存在42 如何编写一个查询来为我查找42?此查询将获取存在于所有personnelId中的task
#People
,其中包含以下内容:
PersonnelId, TaskId
200 40
200 41
200 **42**
300 **42**
300 45
400 41
400 **42**
400 60
因此,请注意,所有三组人员中都存在42
如何编写一个查询来为我查找42?此查询将获取存在于所有personnelId中的taskid
Select taskid
From tbl
Group by taskid
Having count(distinct PersonnelId) =
(select count(distinct PersonnelId) from tbl)