Select GroupId,count(distinct GroupProgramYearParticipantID)as [ChildAddedcurrent]
from #temp1
Where (MonthFlag = 0) and (ParticipantTypeName = 'child')
and (GroupProgramYearParticipantID not in
(Select distinct GroupProgramYearParticipantID
from #temp1
Where (MonthFlag = 1) and (ParticipantTypeName = 'child')))
group by groupId
内部选择查询检查表中的所有 groupid,但我希望它检查外部选择查询中引用的每个相应组。