I work on SQL Server 2014. I need to get rows that have source type 484456.
When group by two columns, group by
GivenPartNumber_Non
and
vcompanyid
.
So, I need to make
select
query display every group of rows by
GivenPartNumber_Non
and
vcompanyid
have source type 484456 only may be this group 1 row or 2 rows or 3 rows or more, etc. Anyway, I need to retrieve it.
Sample data:
create table #notmappedsources
(
GivenPartNumber_Non varchar(200),
vcompanyid int,
SourceType int
)
insert into #notmappedsources(GivenPartNumber_Non,vcompanyid,SourceType)
values
('ADFGH22',1233,484456),
('ADFGH22',1233,484456),
('ADFGH22',1233,484456),
('XFDY990',5489,484456),
('XFDY990',5489,484456),
('GX84322',2549,484456),
('LKHG23',3201,484320),
('LKHG23',3201,484320),
('LKHG23',3201,484320),
('DGHJ66',7041,484320),
('FDYH36',8901,484320),
('FDYH36',8901,484320),
('MNH32',5601,489561),
('MNH32',5601,489561),
('MNH32',5601,484456),
('NUI34',9076,489561),
('KLMD33',5022,489561),
('KLMD33',5022,484456)
The expected result is as below:
GivenPartNumber_Non vcompanyid SourceType
ADFGH22 1233 484456
ADFGH22 1233 484456
ADFGH22 1233 484456
XFDY990 5489 484456
XFDY990 5489 484456
GX84322 2549 484456
What I have tried:
select GivenPartNumber_Non,vcompanyid from #notmappedsources
where SourceType=484456
group by GivenPartNumber_Non,vcompanyid