我在 sql server 2017 上工作,我遇到了我无法解决的问题partnumber
至少具有源类型website
并且至少具有stockid
equal 1
每个partnumber
所以还有另一个含义,我需要获得具有stockid
1
和source type
website
所以我需要进行选择查询获取必须具有源类型website
和库存=1
的零件编号Part number
样本数据
create table #stockyes
(
PartNumber varchar(100),
sourcetype varchar(100),
stockid tinyint
)
insert into #stockyes(PartNumber,sourcetype,stockid)
values
(1233,'Website',1),
(1233,'Website',0),
(1233,'Datasheet',1),
(8901,'Website',1),
(8901,'Website',0),
(9015,'Website',1),
(7801,'Website',1),
(7801,'Website',1),
(9401,'Datasheet',0),
(5688,'Datasheet',0),
(5688,'Datasheet',0),
(5688,'Lifecycle',2),
(5688,'Lifecycle',2),
(8409,'Lifecycle',1),
(6703,'Website',0),
(6703,'Website',0),
(6703,'Website',0),
(3099,'Website',0),
(3099,'Website',0),
(8541,'Website',0)
预期结果
一种方法是使用存在:
演示
编辑要获得不同的零件编号,请仅使用:
演示