gpt4 book ai didi

tsql - SQL 查询组合过滤两个字段

转载 作者:行者123 更新时间:2023-12-04 12:42:41 24 4
gpt4 key购买 nike

ArticleNumber   Company Storage
01-01227 12 2
01-01227 2 1 'filtered by company/storage in combination
01-01227 5 1
01-01227 12 1 'filtered by company/storage in combination
01-44444 5 4 'filtered by not match the articlenumber

我想过滤包含( company = 12 storage = 1 )和( company = 2 storage = 1 )的行,也将过滤掉结果集 articlenr

这就是我想出的,但确定必须有一种更简单的方法来进行查询吗?
SELECT  * FROM    MyTable 
where
(Company=2 and Storage<>1 and ArticleNumber='01-01227')
or
(Company=12 and Storage<>1 and ArticleNumber='01-01227')
or
(Company<>2 and Company<>12 and ArticleNumber='01-01227')

我追求的结果:
ArticleNumber   Company Storage
01-01227 12 2
01-01227 5 1

最佳答案

SELECT * FROM MyTable
WHERE ArticleNumber='01-01227'
AND (Company NOT IN (2,12) OR Storage <> 1)

关于tsql - SQL 查询组合过滤两个字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9500694/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com