如何为SQL的Where语句筛选多个值

如何为SQL的Where语句筛选多个值,sql,tsql,Sql,Tsql,在T-SQL中的where语句中,下面的查询有什么帮助吗 我在表中有ID和Product字段,其中条件需要排除不在('11'、'22'、'33')中的ID,仅当for Product='c' Select ID,Product from Supplier where 1=1 and Product in('A','B','C') 陈述应当呈现 and ID not in('11','22','33') 当产品class='C',排除ID时应为使用不存在 Select ID,Product f

在T-SQL中的where语句中,下面的查询有什么帮助吗

我在表中有ID和Product字段,其中条件需要排除不在('11'、'22'、'33')中的ID,仅当for Product='c'

Select ID,Product from Supplier
where 1=1 and Product in('A','B','C')
陈述应当呈现

and ID not in('11','22','33')
当产品class='C',排除ID时应为使用不存在

Select ID,Product from Supplier a
where 1=1 and Product in('A','B','C') and not exists 
(
  select 1 from supplier b where a.product=b.product and b.product='C' and
  b.ID in('11','22','33')
)

使用
不存在

 select * from table t1
 where not exists ( select 1 from table t2 where t1.Product=t2.Product
                              and t2.Product='C'
                              and ID in('11','22','33')
                  )
  and Product in('A','B','C')
这很简单

SELECT * FROM Supplier WHERE Product !='c' OR ( Id NOT IN(11,22,33) AND Product= 'c') 
添加您的新条件

SELECT * FROM Supplier WHERE (Product in ('a','b','c') and Product !='c' ) OR ( Id NOT IN(11,22,33) AND Product= 'c')
你可以试试这个

Select ID, Product from Supplier
where 1=1 and 
    ( Product in('A','B')
        OR ( Product = 'C' AND ID not in('11','22','33')) )

感谢您的回答,我期望得到以下结果:1)它需要在('A','B','C')中过滤产品的Where语句//该语句应该提供2)另一个条件,它仅在Product=C时特定&排除不在('11','22','33'中的ID)。请替换从供应商处选择的查询*,其中(产品在('a','b','c')和产品!='c')或(Id不在(11,22,33)和产品在('c'))