I work on sql server 2012 i need to get part id that have two different source type per same part .
but part have two different source type per part
and it must have one source type from two source type equal 8901 .
sample data
create table #temp
(
partid int,
sourcetypeid int
)
insert into #temp(partid,sourcetypeid)
values
(1290,5012),
(1290,5012),
(1290,8901),
(3501,5402),
(3501,74430),
(7001,8901),
(7321,8900),
(2040,5090),
(2040,5400),
(7321,7400),
(9110,8901),
(9110,8901)
what i try
select partid from #temp
where sourcetypeid=8901
group by partid
having count(distinct sourcetypeid)=2
but it return null
expected result