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
Run Code Online (Sandbox Code Playgroud)
我想过滤,以便将包含(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')
Run Code Online (Sandbox Code Playgroud)
我追求的结果:
ArticleNumber Company Storage
01-01227 12 2
01-01227 5 1
Run Code Online (Sandbox Code Playgroud)
这将返回您正在寻找的内容:
select * from t
where articleNumber = '01-01227' and (
(company != 12 or storage != 1) and
(company != 2 or storage != 1)
)
Run Code Online (Sandbox Code Playgroud)
结果:
ARTICLENUMBER COMPANY STORAGE
01-01227 12 2
01-01227 5 1
Run Code Online (Sandbox Code Playgroud)
无需加入此解决方案,这使其保持相当快的速度和性能。此外,您可以轻松地成对添加限制。
| 归档时间: |
|
| 查看次数: |
5388 次 |
| 最近记录: |